Skip to content

Commit 45a9755

Browse files
jniocheclaude
andauthored
Fix double-close race on static client in OpenSearch AbstractSpout (#1864)
The static client field is initialized under synchronized(AbstractSpout.class), but close() was unsynchronized, allowing multiple spout instances to close the same client concurrently. Additionally, client was never set to null after closing, so the null check provided no protection against double-close. Synchronize close() on AbstractSpout.class and set client to null after closing. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c523032 commit 45a9755

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • external/opensearch/src/main/java/org/apache/stormcrawler/opensearch/persistence

‎external/opensearch/src/main/java/org/apache/stormcrawler/opensearch/persistence/AbstractSpout.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,14 @@ public void fail(Object msgId) {
225225

226226
@Override
227227
public void close() {
228-
if (client != null) {
229-
try {
230-
client.close();
231-
} catch (IOException e) {
232-
LOG.error("Exception caught when closing client", e);
228+
synchronized (AbstractSpout.class) {
229+
if (client != null) {
230+
try {
231+
client.close();
232+
} catch (IOException e) {
233+
LOG.error("Exception caught when closing client", e);
234+
}
235+
client = null;
233236
}
234237
}
235238
}

0 commit comments

Comments
 (0)