Tighten up lock release logic on I/O and other exceptions
Make version in plugin.yml string so that 0.20 isn't 0.2
This commit is contained in:
parent
f118ada39e
commit
48fea32500
9 changed files with 163 additions and 156 deletions
|
|
@ -131,7 +131,6 @@ public class HttpServerConnection extends Thread {
|
|||
HttpRequest request = new HttpRequest();
|
||||
request.rmtaddr = rmtaddr;
|
||||
if (!readRequestHeader(in, request)) {
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +173,6 @@ public class HttpServerConnection extends Thread {
|
|||
}
|
||||
|
||||
if (handler == null) {
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -186,10 +184,7 @@ public class HttpServerConnection extends Thread {
|
|||
throw e;
|
||||
} catch (Exception e) {
|
||||
Log.severe("HttpHandler '" + handler + "' has thown an exception", e);
|
||||
if (socket != null) {
|
||||
out.flush();
|
||||
socket.close();
|
||||
}
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -211,37 +206,28 @@ public class HttpServerConnection extends Thread {
|
|||
if (responseBody == null) {
|
||||
Debug.debug("Response was given without Content-Length by '" + handler + "' for path '" + request.path + "'.");
|
||||
out.flush();
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
out.flush();
|
||||
|
||||
if (!isKeepalive) {
|
||||
out.flush();
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
} catch (Exception e) {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
Log.severe("Exception while handling request: ", e);
|
||||
e.printStackTrace();
|
||||
return;
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,20 +111,13 @@ public abstract class FileHandler implements HttpHandler {
|
|||
while ((readBytes = fileInput.read(readBuffer)) > 0) {
|
||||
out.write(readBuffer, 0, readBytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
freeReadBuffer(readBuffer);
|
||||
if(fileInput != null) {
|
||||
closeFileInput(path, fileInput);
|
||||
fileInput = null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
if (fileInput != null) {
|
||||
try { closeFileInput(path, fileInput); fileInput = null; } catch (IOException ex) { }
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,12 @@ public class FilesystemHandler extends FileHandler {
|
|||
protected InputStream getFileInput(String path, HttpRequest request, HttpResponse response) {
|
||||
File file = new File(root, path);
|
||||
FileLockManager.getReadLock(file);
|
||||
FileInputStream result = null;
|
||||
try {
|
||||
if (file.getCanonicalPath().startsWith(root.getAbsolutePath()) && file.isFile()) {
|
||||
FileInputStream result;
|
||||
try {
|
||||
result = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
FileLockManager.releaseReadLock(file);
|
||||
return null;
|
||||
}
|
||||
response.fields.put(HttpField.ContentLength, Long.toString(file.length()));
|
||||
|
|
@ -38,14 +37,17 @@ public class FilesystemHandler extends FileHandler {
|
|||
}
|
||||
} catch(IOException ex) {
|
||||
Log.severe("Unable to get canoical path of requested file.", ex);
|
||||
} finally {
|
||||
if(result == null) FileLockManager.releaseReadLock(file);
|
||||
}
|
||||
FileLockManager.releaseReadLock(file);
|
||||
return null;
|
||||
}
|
||||
protected void closeFileInput(String path, InputStream in) throws IOException {
|
||||
super.closeFileInput(path, in);
|
||||
File file = new File(root, path);
|
||||
FileLockManager.releaseReadLock(file);
|
||||
try {
|
||||
super.closeFileInput(path, in);
|
||||
} finally {
|
||||
File file = new File(root, path);
|
||||
FileLockManager.releaseReadLock(file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue