diff --git a/handler.go b/handler.go index 7cf36e1f1dbe71d75d16c9695ee66e373a17f756..d0be5cbd3483033248fa7b807c7988622c75842f 100644 --- a/handler.go +++ b/handler.go @@ -320,11 +320,11 @@ func (h *handler) handleSubscribe(cp *callProc, r *Request) *Response { // Install notifier in context so the subscription handler can find it. n := &Notifier{h: h, namespace: namespace, idgen: randomIDGenerator()} cp.notifiers = append(cp.notifiers, n) - req := r.WithContext(cp.ctx) // now actually run the handler - req = req.WithContext( - context.WithValue(req.ctx, notifierKey{}, n), + req := r.WithContext( + context.WithValue(r.ctx, notifierKey{}, n), ) + mw = NewReaderResponseWriterMsg(req) h.reg.ServeRPC(mw, req) return mw.Response() } diff --git a/router_response.go b/router_response.go index b3cf35240fe83585fbe1a6405f80620946ed2921..839e51e63e4b27713711b3375ad5e3b02ee3db4c 100644 --- a/router_response.go +++ b/router_response.go @@ -108,6 +108,9 @@ func (w *ResponseWriterMsg) Send(args any, e error) (err error) { } func (w *ResponseWriterMsg) Notify(args any) (err error) { + if w.n == nil { + w.n, _ = NotifierFromContext(w.r.ctx) + } if w.s == nil || w.n == nil { return ErrSubscriptionNotFound }