KafkaSaur/kafkaSaur

Uncaught (in promise) BadResource: Bad resource ID (broker disconnected) on confluent cloud

Opened this issue · 0 comments

Cool Library! I found after exactly 10 minutes of inactivity on confluent cloud, the library crashes with error:

Error: Uncaught (in promise) BadResource: Bad resource ID
    const write = await this.conn?.write(data);
                                   ^
    at write (ext:deno_net/01_net.js:58:21)
    at TlsConn.write (ext:deno_net/01_net.js:130:12)
    at CustomSocket.write (https://deno.land/x/kafkasaur@v0.0.7/src/network/socketClass.ts:61:36)
    at Object.sendRequest (https://deno.land/x/kafkasaur@v0.0.7/src/network/connection.ts:366:33)
    at SocketRequest.send [as sendRequest] (https://deno.land/x/kafkasaur@v0.0.7/src/network/requestQueue/index.ts:153:23)
    at SocketRequest.send (https://deno.land/x/kafkasaur@v0.0.7/src/network/requestQueue/socketRequest.ts:88:10)
    at RequestQueue.sendSocketRequest (https://deno.land/x/kafkasaur@v0.0.7/src/network/requestQueue/index.ts:182:19)
    at RequestQueue.push (https://deno.land/x/kafkasaur@v0.0.7/src/network/requestQueue/index.ts:162:12)
    at https://deno.land/x/kafkasaur@v0.0.7/src/network/connection.ts:360:29
    at new Promise (<anonymous>)

BadResource indicates the underlying socket has been closed by the broker which makes sense for a hosted SAS platform.

I have done some bodging and "fixed" this myself - it seems to work in my own very limited testing.

Approaches ruled out:

  • Socket-level keep-alive (this only works for non-TLS connections - denoland/deno#13543)
  • Try to throw an error somehow so that producers know to just tear down the whole kafkasaur instance and restart. Limited success - in some cases was able to bubble up an error but not reliably. Subsequent produce attempts blocked forever
  • Try to reconnect and then resend from inside socketClass.ts - blocks forever