408077 HashSessionManager leaves file handles open after being stopped

This commit is contained in:
Jan Bartel 2013-05-16 15:39:50 +10:00
parent 8a1ea2f69c
commit 51c1017b3d
2 changed files with 41 additions and 33 deletions

View File

@ -37,6 +37,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Logger;
@ -520,8 +521,7 @@ public class HashSessionManager extends AbstractSessionManager
}
finally
{
if (in != null)
try {in.close();} catch (Exception x) {__log.ignore(x);}
if (in != null) IO.close(in);
if (error != null)
{
@ -568,6 +568,8 @@ public class HashSessionManager extends AbstractSessionManager
* defaultReadObject
*/
DataInputStream in = new DataInputStream(is);
try
{
String clusterId = in.readUTF();
in.readUTF(); // nodeId
long created = in.readLong();
@ -581,18 +583,27 @@ public class HashSessionManager extends AbstractSessionManager
if (size>0)
{
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(in);
try
{
for (int i=0; i<size;i++)
{
String key = ois.readUTF();
Object value = ois.readObject();
session.setAttribute(key,value);
}
ois.close();
}
else
in.close();
finally
{
IO.close(ois);
}
}
return session;
}
finally
{
IO.close(in);
}
}
/* ------------------------------------------------------------ */

View File

@ -121,6 +121,7 @@ public class HashedSession extends AbstractSession
fos = new FileOutputStream(file);
willPassivate();
save(fos);
IO.close(fos);
if (reactivate)
didActivate();
else
@ -129,17 +130,12 @@ public class HashedSession extends AbstractSession
catch (Exception e)
{
saveFailed(); // We won't try again for this session
if (fos != null)
{
// Must not leave the file open if the saving failed
IO.close(fos);
// No point keeping the file if we didn't save the whole session
file.delete();
if (fos != null) IO.close(fos);
if (file != null) file.delete(); // No point keeping the file if we didn't save the whole session
throw e;
}
}
}
}
/* ------------------------------------------------------------ */
public synchronized void save(OutputStream os) throws IOException
{
@ -192,6 +188,7 @@ public class HashedSession extends AbstractSession
fis = new FileInputStream(file);
_idled = false;
_hashSessionManager.restoreSession(fis, this);
IO.close(fis);
didActivate();
@ -202,7 +199,7 @@ public class HashedSession extends AbstractSession
catch (Exception e)
{
LOG.warn("Problem de-idling session " + super.getId(), e);
IO.close(fis);
if (fis != null) IO.close(fis);//Must ensure closed before invalidate
invalidate();
}
}