Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix a NullPtr when user closes a writer without connection being… #1454

Merged
merged 1 commit into from Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,6 +27,11 @@

/** Exceptions for Storage Client Libraries. */
public final class Exceptions {
public static class WriterClosedException extends Exception {
public WriterClosedException(String streamName) {
super("Writer closed on: " + streamName);
}
}
/** Main Storage Exception. Might contain map of streams to errors for that stream. */
public static class StorageException extends RuntimeException {

Expand Down
Expand Up @@ -502,11 +502,13 @@ private AppendRowsRequest prepareRequestBasedOnPosition(
}

private void cleanupInflightRequests() {
Throwable finalStatus;
Throwable finalStatus = new Exceptions.WriterClosedException(streamName);
Deque<AppendRequestAndResponse> localQueue = new LinkedList<AppendRequestAndResponse>();
this.lock.lock();
try {
finalStatus = this.connectionFinalStatus;
if (this.connectionFinalStatus != null) {
finalStatus = this.connectionFinalStatus;
}
while (!this.inflightRequestQueue.isEmpty()) {
localQueue.addLast(pollInflightRequestQueue());
}
Expand Down
Expand Up @@ -638,4 +638,12 @@ public void testRetryAfterAllRecordsInflight() throws Exception {
assertEquals(1, appendFuture2.get().getAppendResult().getOffset().getValue());
}
}

@Test
public void testWriterClosedStream() throws Exception {
try (StreamWriter writer = getTestStreamWriter()) {
// Writer is closed without any traffic.
TimeUnit.SECONDS.sleep(1);
}
}
}