{"record":{"id":"17c2d6735729e3f8","repo":"apache/beam","slug":"error-while-attempting-to-remove-bucket-gs-s","errorCode":null,"errorMessage":"Error while attempting to remove bucket gs://%s","messagePattern":"Error while attempting to remove bucket gs://(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java","lineNumber":937,"sourceCode":"              if (errorExtractor.itemNotFound(e) || errorExtractor.accessDenied(e)) {\n                return false;\n              }\n              return RETRY_DETERMINER.shouldRetry(e);\n            }\n          },\n          IOException.class,\n          sleeper);\n    } catch (GoogleJsonResponseException e) {\n      if (errorExtractor.accessDenied(e)) {\n        throw new AccessDeniedException(bucket.getName(), null, e.getMessage());\n      }\n      if (errorExtractor.itemNotFound(e)) {\n        throw new FileNotFoundException(e.getMessage());\n      }\n      throw e;\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new IOException(\n          String.format(\"Error while attempting to remove bucket gs://%s\", bucket.getName()), e);\n    }\n  }\n\n  private static void executeBatches(List<BatchInterface> batches) throws IOException {\n    ExecutorService executor =\n        MoreExecutors.listeningDecorator(\n            new ThreadPoolExecutor(\n                MAX_CONCURRENT_BATCHES,\n                MAX_CONCURRENT_BATCHES,\n                0L,\n                TimeUnit.MILLISECONDS,\n                new LinkedBlockingQueue<>()));\n\n    List<CompletionStage<Void>> futures = new ArrayList<>();\n    for (final BatchInterface batch : batches) {\n      futures.add(MoreFutures.runAsync(batch::execute, executor));\n    }","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java#L919-L955","documentation":"GcsUtilV1.removeBucket converts an InterruptedException during the GCS bucket delete call into this IOException. A 404 is handled separately as FileNotFoundException (bucket already gone), so this error means bucket deletion was interrupted. The interrupt flag is restored before throwing.","triggerScenarios":"Calling removeBucket(bucket) while the executing thread is interrupted, e.g. cleanup running during shutdown or cancellation.","commonSituations":"Temp-bucket cleanup executed in a shutdown hook that gets interrupted; test teardown racing with executor termination.","solutions":["Defer bucket deletion to a non-interruptible cleanup step or external job","Catch IOException and detect InterruptedException cause to skip cleanup gracefully","Ignore failure if the bucket will be garbage-collected by a lifecycle policy"],"exampleFix":"// before\ngcsUtil.removeBucket(bucket);\n// after\ntry {\n  gcsUtil.removeBucket(bucket);\n} catch (IOException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt();\n    LOG.warn(\"Bucket cleanup interrupted; relying on lifecycle policy\");\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (gcsUtil.bucketExists(bucket)) { gcsUtil.removeBucket(bucket); }","typeGuard":"boolean isInterruption(IOException e) { return e.getCause() instanceof InterruptedException; }","tryCatchPattern":"try {\n  gcsUtil.removeBucket(bucket);\n} catch (FileNotFoundException e) {\n  // already deleted; ignore\n} catch (IOException e) {\n  if (e.getCause() instanceof InterruptedException) { Thread.currentThread().interrupt(); }\n  throw e;\n}","preventionTips":["Treat missing-bucket as success in cleanup code","Run deletion outside interruptible shutdown hooks","Use bucket lifecycle rules instead of manual cleanup"],"tags":["gcs","interrupted","concurrency"],"backgroundTag":"thread-interrupted","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}