kanongil / attache

Register Hapi servers as a Consul service.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when stoping hapi server

optii opened this issue · comments

Hi,

I'm getting the following error when using attache.

error: { Error: consul: agent.service.deregister: id required
    at create (node_modules/consul/lib/errors.js:14:5)
    at Object.validation [as Validation] (node_modules/consul/lib/errors.js:26:15)
    at AgentService.deregister (node_modules/consul/lib/agent/service.js:108:45)
    at node_modules/papi/lib/tools.js:108:23
    at node_modules/papi/lib/tools.js:66:14
    at new Promise (<anonymous>)
    at fromCallback (node_modules/papi/lib/tools.js:64:10)
    at AgentService.client.(anonymous function) [as deregister] (node_modules/papi/lib/tools.js:106:18)
    at exports.Consul.module.exports.exports.Consul._serviceApiCall (node_modules/attache/lib/consul.js:154:45)
    at exports.Consul.module.exports.exports.Consul.deregister (node_modules/attache/lib/consul.js:98:17)
    at Object.internals.retryAction (node_modules/attache/lib/index.js:58:42)
    at server.ext (node_modules/attache/lib/index.js:104:40)
    at module.exports.internals.Core._invoke (node_modules/hapi/lib/core.js:423:28)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

I boiled it down to the fact that server.stop(); was being called before there was a connectionId (here). (I am running this in automated test so obviously this is a bit exaggerated as I bring up and down the server very fast, but even with a wait between the server.start & stop I'm still seeing the same error)

Should there be an event triggered when the service is registered correctly with Consul ? or maybe ignore the deregister call if the connectionId isn't set ?

I'm happy to look in to doing a PR to fix if it's something that should be fixed of course.

Thanks,

Yeah, this is a bug. The id will be unset, if the onPostStart hook is never called (for whatever reason).

A PR to fix this would be welcome.

Okay have been having trouble trying to reproduce this bug in a unit test. If the onPostStart is never called then the server.start() should theoretically throw an error as something broke before hand ?
I'm thinking it was more to do with the lowProfile mode maybe and that if the registration in the background has not finished, the server.stop() could be called and the id possibly not set.

I've been playing around with some test to try and create that scenario but without much luck, I've you've got any ideas, i'm a taker