Skip to content

Commit 912da14

Browse files
authored
Merge pull request #2350 from cloudflare/dominik/fixes-starttls-assert-failure
Fixes Socket::startTls assert failure when request IoContext ends.
2 parents 7289bc2 + c66c639 commit 912da14

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: src/workerd/api/sockets.c++

+6-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,12 @@ jsg::Ref<Socket> Socket::startTls(jsg::Lock& js, jsg::Optional<TlsOptions> tlsOp
339339
}
340340
}
341341

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

0 commit comments

Comments
 (0)