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

πŸ› Bug Report β€” Closing TCP socket that didn't finish connection takes ~20 seconds, during which it still counts towards max outbound connection limit #2060

Open
mornveig opened this issue Apr 26, 2024 · 0 comments

Comments

@mornveig
Copy link

Hi team,

Closing TCP socket that didn't finish connection (for example host is unresponsive or port is closed) takes about ~21 seconds both locally and when deployed as cloudflare worker. During that time TCP socket does count towards outbound connection limit, and there seems to be no way currently to forcibly close the socket.

The following code could be used to check the time it takes to close the socket:

import { connect } from 'cloudflare:sockets';

export default {
	async fetch(request, env, ctx) {
		var start_time = Date.now();
		async function socket_connect_close() {
			var socket = connect({ hostname: "8.8.8.8", port: 9999 });
			await socket.close();
			return Date.now() - start_time;
		}
		return new Response(JSON.stringify({'close_time': await socket_connect_close()}), {headers: {"Content-Type": "application/json"}});
	},
};

If connection limit is reached, properly closing unresponsive connection delays all new connections by 21 seconds which sometimes is undesirable.
It'd be great if there was a way to control connect/close timeout for TCP sockets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants