fix(deps): [OCISDEV-834] recover from dead NATS connections in nats-js-kv (#12404)
Bumps the kobergj/plugins nats-js-kv replace pin to fc78af4, which fixes hasConn() to treat a permanently-closed NATS connection as no connection. Previously hasConn() only checked n.conn != nil, so once the client exhausted its reconnect attempts the connection stayed non-nil but dead, initConn() never re-ran, and every KV operation failed with 'nats: connection closed' until the pod was restarted. Signed-off-by: Julian Koberg <julian.koberg@kiteworks.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
31df172eec
commit
9eebf487dc
5 files changed
+48
-6
No files matched your search
+25
-1
@@ -69,6 +69,18 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
|
||||
n.setOption(opts...)
|
||||
|
||||
// register unset connection callback
|
||||
f := n.nopts.ClosedCB
|
||||
n.nopts.ClosedCB = func(c *nats.Conn) {
|
||||
// reset connection
|
||||
n.resetConn()
|
||||
|
||||
// execute the original callback if set
|
||||
if f != nil {
|
||||
f(c)
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
@@ -417,7 +429,19 @@ func (n *natsStore) hasConn() bool {
|
||||
n.RLock()
|
||||
defer n.RUnlock()
|
||||
|
||||
return n.conn != nil
|
||||
// A non-nil conn is not enough: once the client has exhausted its
|
||||
// reconnect attempts the conn is permanently closed but stays non-nil,
|
||||
// which would gate initConn() off forever. Treat a closed connection as
|
||||
// "no connection" so the next operation re-initializes it.
|
||||
return n.conn != nil && !n.conn.IsClosed()
|
||||
}
|
||||
|
||||
// thread safe way to reset the connection.
|
||||
func (n *natsStore) resetConn() {
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
|
||||
n.conn = nil
|
||||
}
|
||||
|
||||
// mustGetDefaultBucket returns the bucket with the given name creating it with default configuration if needed.
|
||||
|
||||
Reference in new issue
Block a user