Skip to content

Commit f77eb6b

Browse files
committed
Removes old Socket::close implementation.
1 parent 1cb7b0b commit f77eb6b

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

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

+1-35
Original file line numberDiff line numberDiff line change
@@ -263,33 +263,7 @@ jsg::Ref<Socket> connectImpl(
263263
return connectImplNoOutputLock(js, kj::mv(fetcher), kj::mv(address), kj::mv(options));
264264
}
265265

266-
// Closes the underlying socket connection. This is an old implementation and will be removed soon.
267-
// See closeImplNew below for the new implementation.
268-
//
269-
// TODO(later): remove once safe
270-
jsg::Promise<void> Socket::closeImplOld(jsg::Lock& js) {
271-
// Forcibly close the readable/writable streams.
272-
auto cancelPromise = readable->getController().cancel(js, kj::none);
273-
auto abortPromise = writable->getController().abort(js, kj::none);
274-
// The below is effectively `Promise.all(cancelPromise, abortPromise)`
275-
return cancelPromise.then(js, [abortPromise = kj::mv(abortPromise), this](jsg::Lock& js) mutable {
276-
return abortPromise.then(js, [this](jsg::Lock& js) {
277-
resolveFulfiller(js, kj::none);
278-
return js.resolvedPromise();
279-
}, [this](jsg::Lock& js, jsg::Value err) {
280-
errorHandler(js, kj::mv(err));
281-
return js.resolvedPromise();
282-
});
283-
}, [this](jsg::Lock& js, jsg::Value err) {
284-
errorHandler(js, kj::mv(err));
285-
return js.resolvedPromise();
286-
});
287-
}
288-
289-
// Closes the underlying socket connection, but only after the socket connection is properly
290-
// established through any configured proxy. This method also flushes the writable stream prior to
291-
// closing.
292-
jsg::Promise<void> Socket::closeImplNew(jsg::Lock& js) {
266+
jsg::Promise<void> Socket::close(jsg::Lock& js) {
293267
if (isClosing) {
294268
return closedPromiseCopy.whenResolved(js);
295269
}
@@ -322,14 +296,6 @@ jsg::Promise<void> Socket::closeImplNew(jsg::Lock& js) {
322296
});
323297
}
324298

325-
jsg::Promise<void> Socket::close(jsg::Lock& js) {
326-
if (util::Autogate::isEnabled(util::AutogateKey::SOCKETS_AWAIT_PROXY_BEFORE_CLOSE)) {
327-
return closeImplNew(js);
328-
} else {
329-
return closeImplOld(js);
330-
}
331-
}
332-
333299
jsg::Ref<Socket> Socket::startTls(jsg::Lock& js, jsg::Optional<TlsOptions> tlsOptions) {
334300
JSG_REQUIRE(!isSecureSocket, TypeError, "Cannot startTls on a TLS socket.");
335301
// TODO: Track closed state of socket properly and assert that it hasn't been closed here.

Diff for: src/workerd/api/sockets.h

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class Socket: public jsg::Object {
8484
}
8585

8686
// Closes the socket connection.
87+
//
88+
// The closure is only performed after the socket connection is properly
89+
// established through any configured proxy. This method also flushes the writable stream prior to
90+
// closing.
8791
jsg::Promise<void> close(jsg::Lock& js);
8892

8993
// Flushes write buffers then performs a TLS handshake on the current Socket connection.

Diff for: src/workerd/util/autogate.c++

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ kj::StringPtr KJ_STRINGIFY(AutogateKey key) {
1313
switch (key) {
1414
case AutogateKey::TEST_WORKERD:
1515
return "test-workerd"_kj;
16-
case AutogateKey::SOCKETS_AWAIT_PROXY_BEFORE_CLOSE:
17-
return "sockets-await-proxy-before-close"_kj;
1816
case AutogateKey::NumOfKeys:
1917
KJ_FAIL_ASSERT("NumOfKeys should not be used in getName");
2018
}

Diff for: src/workerd/util/autogate.h

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace workerd::util {
1313
// Workerd-specific list of autogate keys (can also be used in internal repo).
1414
enum class AutogateKey {
1515
TEST_WORKERD,
16-
// Enable new behaviour of Socket::close (specifically waiting for proxy result before closing).
17-
SOCKETS_AWAIT_PROXY_BEFORE_CLOSE,
1816
NumOfKeys // Reserved for iteration.
1917
};
2018

0 commit comments

Comments
 (0)