@@ -411,6 +411,57 @@ func TestConnectionDrop_AllSubscriptionsNotified(t *testing.T) {
411411 }
412412}
413413
414+ func TestSubscribe_ErrorResponseClosesSubscription (t * testing.T ) {
415+ m := newMockWSServer (t )
416+ defer m .stop ()
417+
418+ c := connectClient (t , m )
419+ defer c .Close ()
420+
421+ type subResult struct {
422+ sub * Subscription
423+ err error
424+ }
425+ ch := make (chan subResult , 1 )
426+ go func () {
427+ sub , err := c .subscribe (
428+ []any {"test" },
429+ nil ,
430+ "testSubscribe" ,
431+ "testUnsubscribe" ,
432+ func (msg []byte ) (any , error ) {
433+ var res SlotResult
434+ err := decodeResponseFromMessage (msg , & res )
435+ return & res , err
436+ },
437+ )
438+ ch <- subResult {sub , err }
439+ }()
440+
441+ var reqID uint64
442+ select {
443+ case msg := <- m .incoming :
444+ id , ok := getUint64WithOk (msg , "id" )
445+ require .True (t , ok , "could not parse request ID from %s" , string (msg ))
446+ reqID = id
447+ case <- time .After (2 * time .Second ):
448+ t .Fatal ("timed out waiting for subscription request" )
449+ }
450+
451+ resp := fmt .Sprintf (`{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":%d}` , reqID )
452+ m .send (t , resp )
453+
454+ r := <- ch
455+ require .NoError (t , r .err )
456+ require .NotNil (t , r .sub )
457+
458+ ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
459+ defer cancel ()
460+ _ , err := r .sub .Recv (ctx )
461+ require .Error (t , err )
462+ require .Contains (t , err .Error (), "Method not found" )
463+ }
464+
414465func TestConcurrentUnsubscribeAndConnectionDrop_NoPanic (t * testing.T ) {
415466 m := newMockWSServer (t )
416467 defer m .stop ()
0 commit comments