Fixes #1167 - NPE while completing a reset HTTP/2 stream.

This commit is contained in:
Simone Bordet 2016-12-14 11:09:10 +01:00
parent 3a3978f86b
commit 98fad34ca0
1 changed files with 14 additions and 7 deletions

View File

@ -86,7 +86,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void headers(HeadersFrame frame, Callback callback)
{
if (!checkWrite(callback))
if (!startWrite(callback))
return;
session.frames(this, this, frame, Frame.EMPTY_ARRAY);
}
@ -100,7 +100,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void data(DataFrame frame, Callback callback)
{
if (!checkWrite(callback))
if (!startWrite(callback))
return;
session.data(this, this, frame);
}
@ -114,7 +114,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
session.frames(this, callback, frame, Frame.EMPTY_ARRAY);
}
private boolean checkWrite(Callback callback)
private boolean startWrite(Callback callback)
{
if (writing.compareAndSet(null, callback))
return true;
@ -381,15 +381,22 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback
@Override
public void succeeded()
{
Callback callback = writing.getAndSet(null);
callback.succeeded();
Callback callback = endWrite();
if (callback != null)
callback.succeeded();
}
@Override
public void failed(Throwable x)
{
Callback callback = writing.getAndSet(null);
callback.failed(x);
Callback callback = endWrite();
if (callback != null)
callback.failed(x);
}
private Callback endWrite()
{
return writing.getAndSet(null);
}
private void notifyData(Stream stream, DataFrame frame, Callback callback)