From f77eb6b2161bf272eaefb97725ed8bc4eb6623df Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Mon, 12 Feb 2024 11:45:36 +0000 Subject: [PATCH] Removes old Socket::close implementation. --- src/workerd/api/sockets.c++ | 36 +---------------------------------- src/workerd/api/sockets.h | 4 ++++ src/workerd/util/autogate.c++ | 2 -- src/workerd/util/autogate.h | 2 -- 4 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/workerd/api/sockets.c++ b/src/workerd/api/sockets.c++ index 49a5b3f1dcd..394efe08662 100644 --- a/src/workerd/api/sockets.c++ +++ b/src/workerd/api/sockets.c++ @@ -263,33 +263,7 @@ jsg::Ref connectImpl( return connectImplNoOutputLock(js, kj::mv(fetcher), kj::mv(address), kj::mv(options)); } -// Closes the underlying socket connection. This is an old implementation and will be removed soon. -// See closeImplNew below for the new implementation. -// -// TODO(later): remove once safe -jsg::Promise Socket::closeImplOld(jsg::Lock& js) { - // Forcibly close the readable/writable streams. - auto cancelPromise = readable->getController().cancel(js, kj::none); - auto abortPromise = writable->getController().abort(js, kj::none); - // The below is effectively `Promise.all(cancelPromise, abortPromise)` - return cancelPromise.then(js, [abortPromise = kj::mv(abortPromise), this](jsg::Lock& js) mutable { - return abortPromise.then(js, [this](jsg::Lock& js) { - resolveFulfiller(js, kj::none); - return js.resolvedPromise(); - }, [this](jsg::Lock& js, jsg::Value err) { - errorHandler(js, kj::mv(err)); - return js.resolvedPromise(); - }); - }, [this](jsg::Lock& js, jsg::Value err) { - errorHandler(js, kj::mv(err)); - return js.resolvedPromise(); - }); -} - -// Closes the underlying socket connection, but only after the socket connection is properly -// established through any configured proxy. This method also flushes the writable stream prior to -// closing. -jsg::Promise Socket::closeImplNew(jsg::Lock& js) { +jsg::Promise Socket::close(jsg::Lock& js) { if (isClosing) { return closedPromiseCopy.whenResolved(js); } @@ -322,14 +296,6 @@ jsg::Promise Socket::closeImplNew(jsg::Lock& js) { }); } -jsg::Promise Socket::close(jsg::Lock& js) { - if (util::Autogate::isEnabled(util::AutogateKey::SOCKETS_AWAIT_PROXY_BEFORE_CLOSE)) { - return closeImplNew(js); - } else { - return closeImplOld(js); - } -} - jsg::Ref Socket::startTls(jsg::Lock& js, jsg::Optional tlsOptions) { JSG_REQUIRE(!isSecureSocket, TypeError, "Cannot startTls on a TLS socket."); // TODO: Track closed state of socket properly and assert that it hasn't been closed here. diff --git a/src/workerd/api/sockets.h b/src/workerd/api/sockets.h index 27001312328..d53fe7ef2d3 100644 --- a/src/workerd/api/sockets.h +++ b/src/workerd/api/sockets.h @@ -84,6 +84,10 @@ class Socket: public jsg::Object { } // Closes the socket connection. + // + // The closure is only performed after the socket connection is properly + // established through any configured proxy. This method also flushes the writable stream prior to + // closing. jsg::Promise close(jsg::Lock& js); // Flushes write buffers then performs a TLS handshake on the current Socket connection. diff --git a/src/workerd/util/autogate.c++ b/src/workerd/util/autogate.c++ index 79e2fc9ff01..9d4c4bbbc89 100644 --- a/src/workerd/util/autogate.c++ +++ b/src/workerd/util/autogate.c++ @@ -13,8 +13,6 @@ kj::StringPtr KJ_STRINGIFY(AutogateKey key) { switch (key) { case AutogateKey::TEST_WORKERD: return "test-workerd"_kj; - case AutogateKey::SOCKETS_AWAIT_PROXY_BEFORE_CLOSE: - return "sockets-await-proxy-before-close"_kj; case AutogateKey::NumOfKeys: KJ_FAIL_ASSERT("NumOfKeys should not be used in getName"); } diff --git a/src/workerd/util/autogate.h b/src/workerd/util/autogate.h index 37608acf148..aa7fdcfccaa 100644 --- a/src/workerd/util/autogate.h +++ b/src/workerd/util/autogate.h @@ -13,8 +13,6 @@ namespace workerd::util { // Workerd-specific list of autogate keys (can also be used in internal repo). enum class AutogateKey { TEST_WORKERD, - // Enable new behaviour of Socket::close (specifically waiting for proxy result before closing). - SOCKETS_AWAIT_PROXY_BEFORE_CLOSE, NumOfKeys // Reserved for iteration. };