product-microgateway icon indicating copy to clipboard operation
product-microgateway copied to clipboard

[Websockets] APIs with topics not working properly

Open malinthaprasan opened this issue 2 years ago • 1 comments

Description

If we deploy a websocket API with a couple of topics and try to invoke them using the topics, gateway doesn't response properly (either hangs or gives a 400 response)

Steps to Reproduce

  1. Create a websocket API with context: postman, version: 1.0.0, endpoint: wss://ws.postman-echo.com/raw as the endpoint URL and deploy in CC.
  2. Try to invoke after subscribe/keygen: wscat -c wss://localhost:9095/postman/1.0.0 -H "Authorization: Bearer $TOKEN" -n
  3. This can be invoked properly
  4. Now create another websocket API with context: postmantopics, version: 1.0.0, endpoint: wss://ws.postman-echo.com
  5. Try to invoke after subscribe/keygen: wscat -c wss://localhost:9095/postmantopics/1.0.0/raw -H "Authorization: Bearer $TOKEN" -n
  6. This ends up with a 400 response.

If we use a ballerina service as the endpoint and try the same scenario above, the CC hangs without giving a response in the 2nd case.

ws-server.bal

import ballerina/io;
import ballerina/websocket;
service /echo on new websocket:Listener(7070) {
   resource function get .()
                     returns websocket:Service|websocket:Error {
       return new WsService();
   }
}

service class WsService {
    *websocket:Service;
    remote function onTextMessage(websocket:Caller caller,
                                 string text) returns websocket:Error? {
        io:println("\ntext message: " + text);
        return caller->writeTextMessage("You said: " + text);
    }
}

Running: bal run ws-server.bal

Endpoint: ws://:7070/echo

Version

1.1.0

Environment Details (with versions)

No response

Relevant Log Output

No response

Related Issues

No response

Suggested Labels

No response

malinthaprasan avatar Sep 06 '22 07:09 malinthaprasan

I checked the given scenario, after doing steps 4 and 5, got the path logs as below:

[2022-09-08T06:07:36.335Z] 'GET /postmantopics/1.0.0/raw / HTTP/1.1' 502 - 0 150 2170 - '-' '-' '88164b83-4090-4a66-bbe4-cf7ffde65002' 'ws.postman-echo.com' '3.225.70.24:443'

/ means we are not passing /raw path to the actual backend.

Then I add mapping to the topic from /raw to /raw as described here:

[2022-09-08T06:32:59.689Z] 'GET /postmantopics/1.0.0/raw /raw HTTP/1.1' 101 DC 51 29 4621 - '-' '-' '1383ec06-30ea-4783-be78-acd4b07aaaab' 'ws.postman-echo.com' '3.225.70.24:443'

and it worked.

when checked this in a apim pack, it had the same behaviour

Amila-Rukshan avatar Sep 08 '22 06:09 Amila-Rukshan

Closing the issue as the functionality works properly.

pubudu538 avatar Jan 12 '23 12:01 pubudu538