Skip to content

Commit 0fc4f28

Browse files
committed
rfq: store outgoing request before sending message
We store the outgoing request in the request map, so we can interpret any response and map it to the original request. We do this before sending the message, because otherwise we could potentially receive the response while we're waiting for the atomic lock to be released, which would lead to us not knowing about the request in the first place, and we couldn't map the response.
1 parent 5225722 commit 0fc4f28

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

rfq/stream.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,12 @@ func (h *StreamHandler) HandleOutgoingMessage(
154154
ctx, cancel := h.WithCtxQuitNoTimeout()
155155
defer cancel()
156156

157-
err = h.cfg.PeerMessenger.SendCustomMessage(ctx, lndClientCustomMsg)
158-
if err != nil {
159-
return fmt.Errorf("unable to send message to peer: %w",
160-
err)
161-
}
162-
163-
// Store outgoing requests.
157+
// We store the outgoing request in the request map, so we can interpret
158+
// any response and map it to the original request. We do this before
159+
// sending the message, because otherwise we could potentially receive
160+
// the response while we're waiting for the atomic lock to be released,
161+
// which would lead to us not knowing about the request in the first
162+
// place, and we couldn't map the response.
164163
switch msg := outgoingMsg.(type) {
165164
case *rfqmsg.BuyRequest:
166165
h.outgoingRequests.Store(msg.ID, msg)
@@ -173,6 +172,12 @@ func (h *StreamHandler) HandleOutgoingMessage(
173172
msg.ID.String())
174173
}
175174

175+
err = h.cfg.PeerMessenger.SendCustomMessage(ctx, lndClientCustomMsg)
176+
if err != nil {
177+
return fmt.Errorf("unable to send message to peer: %w",
178+
err)
179+
}
180+
176181
return nil
177182
}
178183

0 commit comments

Comments
 (0)