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

Support request/response timeouts for the HTTP client #1375

Closed
s-ludwig opened this issue Jan 17, 2016 · 4 comments · Fixed by #2344
Closed

Support request/response timeouts for the HTTP client #1375

s-ludwig opened this issue Jan 17, 2016 · 4 comments · Fixed by #2344

Comments

@s-ludwig
Copy link
Member

Ref.: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/29356/

@SingingBush
Copy link

this would be helpful for me

@s-ludwig s-ludwig added the http label Jul 5, 2017
@tchaloupka
Copy link
Contributor

This would definitelly be usefull, for example by accident I found my services blocking each other with the REST call between them.

For example if we have service a with a bug like this:

#!/usr/bin/env dub
/+ dub.sdl:
	name "a"
	dependency "vibe-d" version="~>0.8.3"
	dependency "vibe-d:tls" version="~>0.8.3"
	subConfiguration "vibe-d:tls" "openssl-1.1"
+/

import core.time;
import vibe.core.core;
import vibe.core.log;
import vibe.http.client;
import vibe.http.common;
import vibe.http.router;
import vibe.http.server;
import vibe.stream.operations;

class Foo {}

void runServer()
{
	auto settings = new HTTPServerSettings();
	settings.port = 8081;
	settings.options |= HTTPServerOption.reusePort;
	auto router = new URLRouter;
	router.get("/test", &test);
	router.get("/testb", &testb);

	listenHTTP(settings, router);
}

void test(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
	logDiagnostic("test call in");
	scope (exit) logDiagnostic("test call end");

	synchronized (Foo.classinfo)
	{
		logDiagnostic("test call synchronized in");
		scope (exit) logDiagnostic("test call synchronized end");

		requestHTTP("http://localhost:8082/test",
			(scope HTTPClientRequest req) {},
			(scope HTTPClientResponse res) {
				logInfo("Response: %s", res.bodyReader.readAllUTF8());
			}
		);
	}

	res.writeBody("test completed\n");
}

void testb(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
	logDiagnostic("testb call in");
	scope (exit) logDiagnostic("testb call end");

	synchronized (Foo.classinfo)
	{
		logDiagnostic("testb call synchronized in");
		sleep(1.seconds);
		scope (exit) logDiagnostic("testb call synchronized end");
	}

	res.writeBody("a\n");
}

void main()
{
	runWorkerTaskDist(&runServer);
	runApplication();
}

And then service b:

#!/usr/bin/env dub
/+ dub.sdl:
	name "b"
	dependency "vibe-d" version="~>0.8.3"
	dependency "vibe-d:tls" version="~>0.8.3"

	subConfiguration "vibe-d:tls" "openssl-1.1"
+/

import vibe.core.core;
import vibe.core.log;
import vibe.http.client;
import vibe.http.common;
import vibe.http.router;
import vibe.http.server;
import vibe.stream.operations;

void test(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
	logDiagnostic("test call in");
	scope (exit) logDiagnostic("test call end");

	requestHTTP("http://localhost:8081/testb",
		(scope HTTPClientRequest req) {},
		(scope HTTPClientResponse res) {
			logInfo("Response: %s", res.bodyReader.readAllUTF8());
		}
	);

	res.writeBody("b\n");
}

void main()
{
	auto settings = new HTTPServerSettings();
	settings.port = 8082;
	auto router = new URLRouter;
	router.get("/test", &test);

	listenHTTP(settings, router);

	runApplication();
}

And then requested curl http://localhost:8081/test
We can easily end up with a service deadlock as timeout never happens.

@AndrejMitrovic
Copy link
Contributor

@s-ludwig: Hey! I was looking into whether vibe.d has support for time-outs and found this old issue. From what I can tell, there is some code that supports timeouts (I see things like bool waitForData(Duration timeout = Duration.max) in the code), but I'm not sure if I'm looking in the right module.

If timeouts are still not supported, could you give some brief guidance on what approach to take to implement them? Cheers!

@denizzzka
Copy link
Contributor

denizzzka commented Aug 6, 2019

Looks like http://code.dlang.org/packages/requests implements this kind of timeouts by TCPStream usage

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

Successfully merging a pull request may close this issue.

5 participants