deeplay-io / nice-grpc

A TypeScript gRPC library that is nice to you

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

server.listen can't be retried in the case of binding failure

lilwilsond2 opened this issue · comments

commented

even if the first call to server.listen fails when server.bindAsync rejects, you are unable to try again

while (count++ < maxRetries) {
    try {
      // this listen call will fail if the port is already occupied
      const port = await server.listen(`0.0.0.0:${getRandomIntegerInRange({ max: 53_000, min: 52_000 })}`);
      return { port, server };
    } catch (e) {
      // this can work by calling shutdown or forceShutdown here, but that seems a bit wasteful
      // server.forceShutdown();
      if (e.message !== 'No address added out of total 1 resolved') {
        throw e;
      }
    }
  }

i proposed just using port 0 and letting the os assign a port, but other members of my team weren't comfortable with that so i'm not opposed to just using the shutdown maneuver. The overall behavior just seemed unintuitive to me.

Thank you for your report. How does this inability to try again manifests itself? What error do you get?

commented

server.listen() has already been called which i assume is coming from here, but i could definitely be wrong

Please try 📦 nice-grpc@2.1.2