digitalmars.D.learn - vibe.d requestHTTP in static this causes infinite loop?
- Vijay Nayar (39/39) May 19 2022 I've encountered an unusual behavior that I have no good
- =?UTF-8?Q?Ali_=c3=87ehreli?= (7/10) May 19 2022 I am not experienced with vibe.d.
- bauss (4/16) May 19 2022 Static constructor shouldn't be there at all in this case, since
- Vijay Nayar (3/15) May 20 2022 Very clever, you were exactly right. I had not thought of that,
I've encountered an unusual behavior that I have no good
explanation for. Consider the following code example:
```d
import vibe.core.log : logInfo;
import vibe.http.client : requestHTTP, HTTPClientRequest,
HTTPClientResponse;
import vibe.http.common : HTTPMethod;
import vibe.stream.operations : readAllUTF8;
void doThing() {
requestHTTP("http://example.com/",
(scope HTTPClientRequest req) {
logInfo("Setting request method.");
req.method = HTTPMethod.GET;
},
(scope HTTPClientResponse res) {
logInfo("Log point 1");
string data = res.bodyReader.readAllUTF8();
logInfo("Log point 2: %s", data);
});
}
static this() {
logInfo("--- static this() ---");
doThing();
}
void main(string[] args) {
logInfo("--- main() ---");
doThing();
}
```
The output of this program is actually an infinite loop with
output of the form:
```
[Eventcore DNS Lookup(----) INF] --- static this() ---
[Eventcore DNS Lookup(----) INF] --- static this() ---
```
If I remove the call from `static this()`, then the web call
works as normal. Any idea why calling vibe.d's `requestHTTP`
function inside of a module's static construction would cause an
infinite loop?
May 19 2022
On 5/19/22 16:44, Vijay Nayar wrote:If I remove the call from `static this()`, then the web call works as normal. Any idea why calling vibe.d's `requestHTTP` function inside of a module's static construction would cause an infinite loop?I am not experienced with vibe.d. 'static this' is executed per thread. If requestHTTP starts a new thread, then I can see how you would be in an infinite loop. I wonder whether it should be 'shared static this' (which is executed once per program, not per thread). Ali
May 19 2022
On Friday, 20 May 2022 at 01:41:59 UTC, Ali Çehreli wrote:On 5/19/22 16:44, Vijay Nayar wrote:Static constructor shouldn't be there at all in this case, since it's not constructing anything. He shouldn't really use anything but main in this case.If I remove the call from `static this()`, then the web callworks asnormal. Any idea why calling vibe.d's `requestHTTP` functioninside of amodule's static construction would cause an infinite loop?I am not experienced with vibe.d. 'static this' is executed per thread. If requestHTTP starts a new thread, then I can see how you would be in an infinite loop. I wonder whether it should be 'shared static this' (which is executed once per program, not per thread). Ali
May 19 2022
On Friday, 20 May 2022 at 01:41:59 UTC, Ali Çehreli wrote:On 5/19/22 16:44, Vijay Nayar wrote:Very clever, you were exactly right. I had not thought of that, but that is indeed what was happening.If I remove the call from `static this()`, then the web callworks asnormal. Any idea why calling vibe.d's `requestHTTP` functioninside of amodule's static construction would cause an infinite loop?I am not experienced with vibe.d. 'static this' is executed per thread. If requestHTTP starts a new thread, then I can see how you would be in an infinite loop. I wonder whether it should be 'shared static this' (which is executed once per program, not per thread). Ali
May 20 2022









bauss <jj_1337 live.dk> 