Skip to content

Commit

Permalink
Merge pull request #11 from FusionAuth/degroff/connection-reset-by-peer
Browse files Browse the repository at this point in the history
degroff/connection reset by peer
  • Loading branch information
robotdan authored Jul 27, 2023
2 parents 9d2a5cc + 7ef0d69 commit 8800865
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
9 changes: 6 additions & 3 deletions build.savant
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* language governing permissions and limitations under the License.
*/
jackson5Version = "3.0.1"
restifyVersion = "4.1.2"
restifyVersion = "4.2.0"
testngVersion = "7.8.0"

project(group: "io.fusionauth", name: "java-http", version: "0.2.0", licenses: ["ApacheV2_0"]) {
Expand Down Expand Up @@ -62,9 +62,12 @@ release = loadPlugin(id: "org.savantbuild.plugin:release-git:2.0.0-RC.6")
pom = loadPlugin(id: "org.savantbuild.plugin:pom:2.0.0-RC.6")

java.settings.javaVersion = "17"
java.settings.compilerArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED -XDignore.symbol.file"
java
.settings
.compilerArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED -XDignore.symbol.file"
javaTestNG.settings.javaVersion = "17"
javaTestNG.settings.jvmArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED"
javaTestNG
.settings.jvmArguments = "--add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED"
javaTestNG.settings.testngArguments = "-listener io.fusionauth.http.BaseTest\$TestListener"

target(name: "clean", description: "Cleans the build directory") {
Expand Down
4 changes: 2 additions & 2 deletions java-http.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<orderEntry type="module-library" scope="TEST">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/.savant/cache/com/inversoft/restify/4.1.2/restify-4.1.2.jar!/" />
<root url="jar://$MODULE_DIR$/.savant/cache/com/inversoft/restify/4.2.0/restify-4.2.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/.savant/cache/com/inversoft/restify/4.1.2/restify-4.1.2-src.jar!/" />
<root url="jar://$MODULE_DIR$/.savant/cache/com/inversoft/restify/4.2.0/restify-4.2.0-src.jar!/" />
</SOURCES>
</library>
</orderEntry>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>com.inversoft</groupId>
<artifactId>restify</artifactId>
<version>4.1.2</version>
<version>4.2.0</version>
<type>jar</type>
<scope>test</scope>
<optional>false</optional>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/io/fusionauth/http/ClientAbortException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, FusionAuth, All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package io.fusionauth.http;

import java.io.IOException;

/**
* An IOException that is most likely caused by the client closing a socket.
* <p>
* For example:
* <code>java.io.IOException: Connection reset by peer</code>
*/
public class ClientAbortException extends IOException {
public ClientAbortException(IOException e) {
super(e);
}
}
21 changes: 19 additions & 2 deletions src/main/java/io/fusionauth/http/server/HTTPServerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;

import io.fusionauth.http.ClientAbortException;
import io.fusionauth.http.ParseException;
import io.fusionauth.http.log.Logger;
import io.fusionauth.http.util.ThreadPool;
Expand Down Expand Up @@ -191,6 +192,10 @@ public void run() {
instrumenter.badRequest();
}

cancelAndCloseKey(key);
} catch (ClientAbortException e) {
// A client abort exception is common and should not be error logged.
logger.debug("A client related exception was thrown during processing", e);
cancelAndCloseKey(key);
} catch (Throwable t) {
logger.error("An exception was thrown during processing", t);
Expand Down Expand Up @@ -287,7 +292,14 @@ private void read(SelectionKey key) throws IOException {
if (state == ProcessorState.Read) {
ByteBuffer buffer = processor.readBuffer();
if (buffer != null) {
int num = client.read(buffer);
int num;
try {
num = client.read(buffer);
} catch (IOException e) {
// This is most likely an exception caused by the client.
throw new ClientAbortException(e);
}

if (num < 0) {
logger.debug("Client terminated the connection. Num bytes is [{}]. Closing connection", num);
state = processor.close(true);
Expand Down Expand Up @@ -320,7 +332,12 @@ private void write(SelectionKey key) throws IOException {
if (state == ProcessorState.Write) {
long num = 0;
if (buffers != null) {
num = client.write(buffers);
try {
num = client.write(buffers);
} catch (IOException e) {
// This is most likely an exception caused by the client.
throw new ClientAbortException(e);
}
}

if (num < 0) {
Expand Down

0 comments on commit 8800865

Please sign in to comment.