From 01da2a306190db51357663a703ff42229354bd4c Mon Sep 17 00:00:00 2001
From: a <a@tuxpa.in>
Date: Tue, 28 Feb 2023 06:24:43 -0600
Subject: [PATCH] notifier fix maybe

---
 handler.go         | 6 +++---
 router_response.go | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/handler.go b/handler.go
index 7cf36e1..d0be5cb 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 b3cf352..839e51e 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
 	}
-- 
GitLab