Skip to content

Commit 836fee0

Browse files
authored
Merge pull request #14 from digitalocean/mdl-ovsdb-crash
ovsdb: don't crash on unhandled callback RPC
2 parents 26d6590 + 8e754ed commit 836fee0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ovsdb/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (c *Client) doCallback(id int, res rpcResponse) {
213213
ch, ok := c.callbacks[id]
214214
if !ok {
215215
// Nobody is listening to this callback.
216-
panicf("OVSDB callback with ID %d has no listeners", id)
216+
return
217217
}
218218

219219
// Return result, clean up channel, and remove this callback.

ovsdb/client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ func TestClientOVSDBError(t *testing.T) {
7373
}
7474
}
7575

76+
func TestClientBadCallback(t *testing.T) {
77+
c, notifC, done := testClient(t, func(_ jsonrpc.Request) jsonrpc.Response {
78+
return jsonrpc.Response{
79+
ID: intPtr(1),
80+
Result: mustMarshalJSON(t, []string{"foo"}),
81+
}
82+
})
83+
defer done()
84+
85+
// Client doesn't have a callback for this ID.
86+
notifC <- &jsonrpc.Response{
87+
Method: "crash",
88+
ID: intPtr(10),
89+
}
90+
91+
if _, err := c.ListDatabases(); err != nil {
92+
t.Fatalf("unexpected error: %v", err)
93+
}
94+
}
95+
7696
func testClient(t *testing.T, fn jsonrpc.TestFunc) (*ovsdb.Client, chan<- *jsonrpc.Response, func()) {
7797
t.Helper()
7898

0 commit comments

Comments
 (0)