gRPC-web ignoring callbacks

51 views
Skip to first unread message

Nicholas Bunn

unread,
Aug 20, 2021, 2:28:02 AM8/20/21
to grpc.io
Hi all,

I'm very new to Javascript and everything frontend (started playing around with it all on Monday so any and every kind of input here would be appreciated). I'm currently trying to set up a login page for a project I'm working on which just verifies that a user exists in a DB, checks the passwords, and generates and returns an auth token if everything checks out. I've written all the logic for this in a Go service that exposes itself on port 50000 (I've also tested this service and know that everything here is working). As per the documentation, I've set up an Envoy proxy that routes JS requests on port 8080 to the Go server at 50000 and, as far as I can tell, this is working too. Using Bloom RPC to test things, I've verified that the Envoy Proxy returns the errors I want when incorrect details are provided and returns the auth token when the correct ones are given. 

```
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;

console.log("Username is: ", username, " and password is: ", password);
var loginService = new LoginServiceClient("http://localhost:8080");

var request = new LoginRequest();

request.setUsername(username);
request.setPassword(password);

loginService.login(request, {}, function (err, res) {
console.log("error:", err, " response:", res);
});
```

I suspect that the issue I'm having lies somewhere between Envoy and my JS frontend. When I make a login request with no username or an incorrect username, the expected error is written to the console in my browser (it's behaving as intended). However, as soon as I make a login request with an existing username (regardless of whether the password is correct or not), nothing is printed to the console. It's as if the response just skips all the code in the callback function.

If I check the log files for my backend services during this behaviour, the requests are going through and being processed perfectly with the responses being sent back through exactly as expected. I'm not too sure how to debug the proxy, and with that being the last place I can trace expected behaviour I suspect the problem is either in my Envoy setup or in the way I'm handling responses in JS. My Envoy setup can be found at https://github.com/NicholasBunn/mastersCaseStudy/blob/main/services/envoyProxy/envoy.yaml - for the most part, it's the same as the Envoy setup given in the documentation.

Am I doing something blatantly wrong here?

Nic

Nicholas Bunn

unread,
Aug 24, 2021, 7:10:27 AM8/24/21
to grpc.io
Been working on other stuff in between trying to solve this but I have a potential source to the odd behaviour. The page reloads whenever requests are sent, is it possible that the requests aren't received when the page is reloaded? If this is the case, the error is caught for an invalid user because the DB response is fast enough to return before the page reloads, but when the user does exist the response is marginally slower such that it returns after the page reload. I've been trying to test this by using event.preventDefault() but this hasn't solved it so I'm not entirely sure.

Nicholas Bunn

unread,
Aug 24, 2021, 12:52:29 PM8/24/21
to grpc.io
I've finally sourced the issue! I was running my Javascript using Live Server, which was forcing a page reload when the requests were sent off. Went back to basics, running without Live Server and everything is working as intended.
Reply all
Reply to author
Forward
0 new messages