fix: don't start a retry timer if connection was closed due to being … · googleapis/java-bigquerystorage@e17ada2
@@ -1273,31 +1273,38 @@ private void doneCallback(Throwable finalStatus) {
12731273 + writerId
12741274 + " Final status: "
12751275 + finalStatus.toString());
1276+boolean closedIdleConnection =
1277+finalStatus.toString().contains("Closing the stream because it has been inactive");
12761278this.lock.lock();
12771279try {
12781280this.streamConnectionIsConnected = false;
12791281this.telemetryMetrics.recordConnectionEnd(
12801282Code.values()[Status.fromThrowable(finalStatus).getCode().ordinal()].toString());
12811283if (connectionFinalStatus == null) {
1282-if (connectionRetryStartTime == 0) {
1284+if (!closedIdleConnection && connectionRetryStartTime == 0) {
12831285connectionRetryStartTime = System.currentTimeMillis();
12841286 }
12851287// If the error can be retried, don't set it here, let it try to retry later on.
12861288if (isConnectionErrorRetriable(Status.fromThrowable(finalStatus).getCode())
12871289&& !userClosed
12881290&& (maxRetryDuration.toMillis() == 0f
1291+ || closedIdleConnection
12891292 || System.currentTimeMillis() - connectionRetryStartTime
12901293<= maxRetryDuration.toMillis())) {
1291-this.conectionRetryCountWithoutCallback++;
1292-this.telemetryMetrics.recordConnectionStartWithRetry();
1294+if (!closedIdleConnection) {
1295+this.conectionRetryCountWithoutCallback++;
1296+this.telemetryMetrics.recordConnectionStartWithRetry();
1297+ }
12931298log.info(
12941299"Connection is going to be reestablished with the next request. Retriable error "
12951300 + finalStatus.toString()
12961301 + " received, retry count "
12971302 + conectionRetryCountWithoutCallback
12981303 + ", millis left to retry "
12991304 + (maxRetryDuration.toMillis()
1300- - (System.currentTimeMillis() - connectionRetryStartTime))
1305+ - (connectionRetryStartTime > 0
1306+ ? System.currentTimeMillis() - connectionRetryStartTime
1307+ : 0))
13011308 + ", for stream "
13021309 + streamName
13031310 + " id:"
@@ -1311,7 +1318,10 @@ private void doneCallback(Throwable finalStatus) {
13111318 + " for stream "
13121319 + streamName
13131320 + " with write id: "
1314- + writerId);
1321+ + writerId
1322+ + ", millis left to retry was "
1323+ + (maxRetryDuration.toMillis()
1324+ - (System.currentTimeMillis() - connectionRetryStartTime)));
13151325 }
13161326 }
13171327 } finally {