Concurrent use of message and we modify it, bad practice, copy it
This commit is contained in:
parent
7968a8eb6d
commit
0348d0eed9
@ -288,7 +288,6 @@ func (h *httpBroker) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
id := req.Form.Get("id")
|
id := req.Form.Get("id")
|
||||||
|
|
||||||
h.RLock()
|
h.RLock()
|
||||||
|
|
||||||
for _, subscriber := range h.subscribers[topic] {
|
for _, subscriber := range h.subscribers[topic] {
|
||||||
if id == subscriber.id {
|
if id == subscriber.id {
|
||||||
// sub is sync; crufty rate limiting
|
// sub is sync; crufty rate limiting
|
||||||
@ -340,12 +339,18 @@ func (h *httpBroker) Publish(topic string, msg *Message, opts ...PublishOption)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Header == nil {
|
m := &Message{
|
||||||
msg.Header = map[string]string{}
|
Header: make(map[string]string),
|
||||||
|
Body: msg.Body,
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Header[":topic"] = topic
|
for k, v := range msg.Header {
|
||||||
b, err := json.Marshal(msg)
|
m.Header[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Header[":topic"] = topic
|
||||||
|
|
||||||
|
b, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user