ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.55k stars 736 forks source link

HTTP client connector hangs when path doesn't start with a '/' #3265

Closed pubudu91 closed 6 years ago

pubudu91 commented 6 years ago

When invoking an HTTP action where the path does not start with '/', the client is kept hanging, waiting for a response. For example, consider the following code snippet:

import ballerina.net.http;

@http:configuration{basePath: "/chuck"}
service<http> chuck {
    http:ClientConnector chuckService = create http:ClientConnector("https://api.chucknorris.io");

    @http:resourceConfig {
        path: "/",
        methods: ["GET"]
    }
    resource chuckJokes(message m) {
        message response = chuckService.get("jokes/random", m);
        reply response;
    }
}

In the above example, the path is given as jokes/random and this causes the client to hang and timeout. If we add the '/' as follows: /jokes/random, it works as expected.

Given below are the trace logs for the error scenario.

[2017-08-31 11:17:24,704]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818] REGISTERED  
[2017-08-31 11:17:24,708]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] ACTIVE  
[2017-08-31 11:17:24,747]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] INBOUND: DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
GET /chuck HTTP/1.1
Host: localhost:9090
Connection: keep-alive
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36
Postman-Token: 3b6e4fd3-6494-c97d-843d-2cd01743a8e7
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8  
[2017-08-31 11:17:24,757]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] INBOUND: EmptyLastHttpContent, 0B  
[2017-08-31 11:17:25,172]  DEBUG {tracelog.http.upstream} - [id: 0xbda106e4, corSrcId: n/a] CLOSE  
[2017-08-31 11:17:25,177]  DEBUG {tracelog.http.upstream} - [id: 0xbda106e4] REGISTERED  
[2017-08-31 11:17:25,179]  DEBUG {tracelog.http.upstream} - [id: 0xbda106e4, corSrcId: n/a] UNREGISTERED  
[2017-08-31 11:19:24,726]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] CLOSE  
[2017-08-31 11:19:24,727]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] INACTIVE  
[2017-08-31 11:19:24,728]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] CLOSE  
[2017-08-31 11:19:24,737]  DEBUG {tracelog.http.downstream} - [id: 0x9f0ce818, corSrcId: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:45228] UNREGISTERED
chamil321 commented 6 years ago

Tested the issue with 0.95.1 ballerina version and works fine.

@http:configuration{basePath: "/chuck"}
service<http> chuck {

    endpoint<http:HttpClient> chuckService {
            create http:HttpClient("https://api.chucknorris.io", {});
        } 
    @http:resourceConfig {
        path: "/",
        methods: ["GET"]
    }
    resource chuckJokes(http:Request req, http:Response res) {
        http:Response resp;
        resp,_ = chuckService.get("jokes/random", {});
        res.forward(resp);
    }
}
shafreenAnfar commented 6 years ago

As per the comment, closing the issue.