pmlopes / yoke

Yoke is a middleware framework for Vert.x
http://pmlopes.github.io/yoke/
Apache License 2.0
157 stars 44 forks source link

NullPointerException in Logger #124

Closed ddossot closed 10 years ago

ddossot commented 10 years ago

With Logger using the default format and not immediate mode, I receive this kind of NPEs:

java.lang.NullPointerException
    at com.jetdrone.vertx.yoke.middleware.Logger.log(Logger.java:99)
    at com.jetdrone.vertx.yoke.middleware.Logger.access$000(Logger.java:27)
    at com.jetdrone.vertx.yoke.middleware.Logger$1.handle(Logger.java:151)
    at com.jetdrone.vertx.yoke.middleware.Logger$1.handle(Logger.java:148)
    at com.jetdrone.vertx.yoke.middleware.YokeResponse.triggerEndHandlers(YokeResponse.java:317)
    at com.jetdrone.vertx.yoke.middleware.YokeResponse.end(YokeResponse.java:510)

for 204 no content type of responses.

I may be wrong but it's as if an early disconnection of the remote client, makes request.remoteAddress().getHostString() return null because the underlying Vert.x request has:

  public InetSocketAddress remoteAddress() {
    return conn.remoteAddress();
  }

which, in the case conn is already disconnected, is null.

I've tried setting immediate to true and of course everything works fine.

So I'm thinking maybe Logger should store more request contextual info that can be nullified so when log is called, all the necessary info is still there.

pmlopes commented 10 years ago

humm then we need some refactoring to get those values as soon as possible...

pmlopes commented 10 years ago

I don't think i can easily reproduce it, can you try to verify if this change fixes it? Thanks!

ddossot commented 10 years ago

Night and day: the issue is gone as far as I can tell :joy_cat:

Thanks a lot :thumbsup: