Great fix. A few minor comments, mostly stylistic.
1. This usage exposes a bit much:
requestChannel.sendResponse(new RequestChannel.Response(request.processor, request, null, RequestChannel.CloseSocket))
I think it might be nicer to have this instead:
Implementation would be the same, it just would just be a little more clear for the user and the response codes can be private.
Likewise in the response object I should be able to
2. These are a little confusing:
val SendResponse: Short = 0
val NoResponse: Short = 1
val CloseSocket: Short = 9
Why is it 0, 1, and 9?
What is the relationship between these and ErrorMapping? It should be clear from reading.
Is there a reason we can't use a case class
case class ResponseAction
case object SendAction extends ResponseAction
case object NoOpAction extends ResponseAction
case object CloseConnectionAction extends ResponseAction
Then to use it
case SendAction => do send
case NoOpAction => read more
case CloseConnectionAction => something
This seems clearer to me and I don't think it is significantly more expensive.
Can we also standardize the usage so that we no longer have the user EITHER give null or NoResponse? It should be one or the other.
3. This logging "Cancelling the request key to notify socket server close the connection due to error handling produce request " is not informative to the user. What does it mean to cancel a key? What broke? What should they do? I also think this should be info unless we want the server admin to take some action (I don't think so, right? This is a normal occurance).
4. The comment "a null response send object" is retained but we are no longer using null to indicate this we are using RequestChannel.NoResponse. I think this comment is actually a little verbose given that we now have a nicely named response action.
5. org.scalatest.TestFailedException: Is there a reason you are giving the full path here instead of importing it
Question on testing, what is the message loss rate with acks=0 under moderate load if we do something like a controlled shutdown with other replicas available?