fix a couple connection closing bugs

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-03-18 11:07:12 +01:00 committed by Simone Bordet
parent 432eddf583
commit 14c6143cdb
2 changed files with 23 additions and 12 deletions

View File

@ -71,16 +71,17 @@ public class QuicSession
return flushed;
}
public void flushFinished(long streamId) throws IOException
{
quicheConnection.feedFinForStream(streamId);
flush();
}
public boolean isFinished(long streamId)
{
return quicheConnection.isStreamFinished(streamId);
}
public void sendFinished(long streamId) throws IOException
{
quicheConnection.feedFinForStream(streamId);
}
public void shutdownInput(long streamId) throws IOException
{
quicheConnection.shutdownStream(streamId, false);
@ -192,11 +193,18 @@ public class QuicSession
{
if (LOG.isDebugEnabled())
LOG.debug("closing QUIC session {}", this);
endpoints.values().forEach(AbstractEndPoint::close);
endpoints.clear();
flusher.close();
quicheConnection.dispose();
connection.onClose(quicheConnectionId);
try
{
endpoints.values().forEach(AbstractEndPoint::close);
endpoints.clear();
flusher.close();
connection.onClose(quicheConnectionId);
}
finally
{
// This call frees malloc'ed memory so make sure it always happens.
quicheConnection.dispose();
}
if (LOG.isDebugEnabled())
LOG.debug("closed QUIC session {}", this);
}

View File

@ -80,16 +80,19 @@ public class QuicStreamEndPoint extends AbstractEndPoint
@Override
public void onClose(Throwable failure)
{
super.onClose(failure);
try
{
session.sendFinished(streamId);
session.flushFinished(streamId);
}
catch (IOException e)
{
if (LOG.isDebugEnabled())
LOG.debug("Error sending FIN on stream {}", streamId, e);
}
// TODO: we must wait until writeFlusher is idle before moving on
// while (!getWriteFlusher().isIdle())
// Thread.onSpinWait();
super.onClose(failure);
session.onClose(streamId);
}