Skip to content

Commit 302cd18

Browse files
MichaelGHSegclaude
andcommitted
Wait for in-flight network uploads to complete on shutdown
The network executor was given only a 1-second termination timeout, which is too short for batches undergoing retries with exponential backoff. In-flight uploads would be abandoned silently, causing failure callbacks to never fire and the CLI to report success=true when retries were exhausted. Introduces NETWORK_TERMINATION_TIMEOUT_S (30s) so shutdown waits long enough for any in-flight batch upload — including its full retry budget — to complete and invoke callbacks before the process exits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 11c54b5 commit 302cd18

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

analytics/src/main/java/com/segment/analytics/internal/AnalyticsClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class AnalyticsClient {
4646
private static final String instanceId = UUID.randomUUID().toString();
4747
private static final int WAIT_FOR_THREAD_COMPLETE_S = 5;
4848
private static final int TERMINATION_TIMEOUT_S = 1;
49+
private static final int NETWORK_TERMINATION_TIMEOUT_S = 30;
4950
private static final long MAX_RATE_LIMITED_SECONDS = 300L;
5051

5152
static {
@@ -298,9 +299,11 @@ private void waitForLooperCompletion() {
298299

299300
public void shutdownAndWait(ExecutorService executor, String name) {
300301
boolean isLooperExecutor = name != null && name.equalsIgnoreCase("looper");
302+
boolean isNetworkExecutor = name != null && name.equalsIgnoreCase("network");
303+
int timeoutSeconds = isNetworkExecutor ? NETWORK_TERMINATION_TIMEOUT_S : TERMINATION_TIMEOUT_S;
301304
try {
302305
executor.shutdown();
303-
boolean terminated = executor.awaitTermination(TERMINATION_TIMEOUT_S, TimeUnit.SECONDS);
306+
boolean terminated = executor.awaitTermination(timeoutSeconds, TimeUnit.SECONDS);
304307
if (terminated) {
305308
log.print(VERBOSE, "%s executor terminated normally.", name);
306309
return;

0 commit comments

Comments
 (0)