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
Comments
this would be helpful for me |
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 |
@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 If timeouts are still not supported, could you give some brief guidance on what approach to take to implement them? Cheers! |
Looks like http://code.dlang.org/packages/requests implements this kind of timeouts by TCPStream usage |
Ref.: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/29356/
The text was updated successfully, but these errors were encountered: