@@ -344,7 +344,7 @@ public void onUncaughtException(Connection connection, Throwable error) {
344
344
}
345
345
else if (handler .shouldRetry && AbortedException .isConnectionReset (error )) {
346
346
HttpClientOperations ops = connection .as (HttpClientOperations .class );
347
- if (ops != null ) {
347
+ if (ops != null && ops . hasSentHeaders () ) {
348
348
// In some cases the channel close event may be delayed and thus the connection to be
349
349
// returned to the pool and later the eviction functionality to remote it from the pool.
350
350
// In some rare cases the connection might be acquired immediately, before the channel close
@@ -353,11 +353,30 @@ else if (handler.shouldRetry && AbortedException.isConnectionReset(error)) {
353
353
// Mark the connection as non-persistent here so that it never be returned to the pool and leave
354
354
// the channel close event to invalidate it.
355
355
ops .markPersistent (false );
356
- ops .retrying = true ;
356
+ // Disable retry if the headers or/and the body were sent
357
+ handler .shouldRetry = false ;
358
+ if (log .isWarnEnabled ()) {
359
+ log .warn (format (connection .channel (),
360
+ "The connection observed an error, the request cannot be " +
361
+ "retried as the headers/body were sent" ), error );
362
+ }
357
363
}
358
- if (log .isDebugEnabled ()) {
359
- log .debug (format (connection .channel (),
360
- "The connection observed an error, the request will be retried" ), error );
364
+ else {
365
+ if (ops != null ) {
366
+ // In some cases the channel close event may be delayed and thus the connection to be
367
+ // returned to the pool and later the eviction functionality to remote it from the pool.
368
+ // In some rare cases the connection might be acquired immediately, before the channel close
369
+ // event and the eviction functionality be able to remove it from the pool, this may lead to I/O
370
+ // errors.
371
+ // Mark the connection as non-persistent here so that it never be returned to the pool and leave
372
+ // the channel close event to invalidate it.
373
+ ops .markPersistent (false );
374
+ ops .retrying = true ;
375
+ }
376
+ if (log .isDebugEnabled ()) {
377
+ log .debug (format (connection .channel (),
378
+ "The connection observed an error, the request will be retried" ), error );
379
+ }
361
380
}
362
381
}
363
382
else if (log .isWarnEnabled ()) {
0 commit comments