-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AsyncContext completion attempt after AsyncListener.onError is called #5675 #5773
Draft
jbescos
wants to merge
1
commit into
eclipse-ee4j:2.x
Choose a base branch
from
jbescos:issue5675
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,14 @@ public void run() { | |
} | ||
} | ||
|
||
static boolean isIOException(Throwable t) { | ||
boolean ioException = false; | ||
while (t != null && !(ioException = t instanceof IOException)) { | ||
t = t.getCause(); | ||
} | ||
return ioException; | ||
} | ||
|
||
/** | ||
* Get the Jersey server runtime background scheduler. | ||
* | ||
|
@@ -669,11 +677,18 @@ public OutputStream getOutputStream(final int contentLength) throws IOException | |
|
||
} catch (final Throwable ex) { | ||
if (response.isCommitted()) { | ||
/** | ||
* We're done with processing here. There's nothing we can do about the exception so | ||
* let's just log it. | ||
*/ | ||
LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_WRITING_RESPONSE_ENTITY(), ex); | ||
if (isIOException(ex)) { | ||
skipFinally = true; | ||
LOGGER.log(Level.WARNING, "Response was sent, but there is IO issue", ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was an issue after the response was committed. |
||
// Connection is broken. Re-throw to the web container to remove the connection. | ||
throw new MappableException("Response was sent, but there is IO issue", ex); | ||
} else { | ||
/** | ||
* We're done with processing here. There's nothing we can do about the exception so | ||
* let's just log it. | ||
*/ | ||
LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_WRITING_RESPONSE_ENTITY(), ex); | ||
} | ||
} else { | ||
skipFinally = true; | ||
if (ex instanceof RuntimeException) { | ||
|
63 changes: 63 additions & 0 deletions
63
core-server/src/test/java/org/glassfish/jersey/server/ServerRuntimeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.server; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.SocketException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ServerRuntimeTest { | ||
|
||
@Test | ||
public void ioExceptionInRoot() { | ||
assertTrue(ServerRuntime.isIOException(new IOException())); | ||
assertTrue(ServerRuntime.isIOException(new IOException(new RuntimeException()))); | ||
} | ||
|
||
@Test | ||
public void ioExceptionInCause() { | ||
assertTrue(ServerRuntime.isIOException(new RuntimeException(new IOException()))); | ||
assertTrue(ServerRuntime.isIOException(new RuntimeException(new RuntimeException(new IOException())))); | ||
} | ||
|
||
@Test | ||
public void unckeckedIOExceptionInCause() { | ||
assertTrue(ServerRuntime.isIOException(new UncheckedIOException(new SocketException()))); | ||
assertTrue(ServerRuntime.isIOException(new RuntimeException(new UncheckedIOException(new SocketException())))); | ||
} | ||
|
||
@Test | ||
public void noIOException() { | ||
assertFalse(ServerRuntime.isIOException(new RuntimeException())); | ||
assertFalse(ServerRuntime.isIOException(new RuntimeException(new RuntimeException()))); | ||
} | ||
|
||
@Test | ||
public void nullException() { | ||
assertFalse(ServerRuntime.isIOException(null)); | ||
} | ||
|
||
@Test | ||
public void nullCause() { | ||
assertFalse(ServerRuntime.isIOException(new RuntimeException((Throwable) null))); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if (response.isCommitted()) {
check is actually kinda racy.The response could be failed in a different thread (eg: from an HTTP/2 goaway), causing the response to be flagged as committed as part of its stream close handling.
This could be false when you check, and then a microsecond later its true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if there is IOException it does not really matter if the response was sent or not, because we cannot respond. Probably we need to skip the finally block in any case for this type of exception.