Skip to content

Commit

Permalink
Fixes Socket::startTls assert failure when request IoContext ends.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Jul 3, 2024
1 parent 866d2f6 commit 916e20c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/workerd/api/sockets.c++
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ jsg::Ref<Socket> Socket::startTls(jsg::Lock& js, jsg::Optional<TlsOptions> tlsOp
}
}

// All non-secure sockets should have a tlsStarter.
// All non-secure sockets should have a tlsStarter. Though since tlsStarter is an IoOwn, if
// the request's IoContext has ended then `tlsStarter` will be null. This can happen if the
// flush operation is taking a particularly long time (EW-8538), so we throw a JSG error if
// that's the case.
JSG_REQUIRE(*tlsStarter != nullptr, "The request has finished before startTls completed.");
auto secureStream = KJ_ASSERT_NONNULL(*tlsStarter)(acceptedHostname).then(
[stream = connectionStream->addWrappedRef()]() mutable -> kj::Own<kj::AsyncIoStream> {
return kj::mv(stream);
Expand Down

0 comments on commit 916e20c

Please sign in to comment.