Skip to content

Commit aab6d2e

Browse files
authored
Merge pull request nsqio#996 from andyxning/fix_memory_leak_with_large_message
nsqd: fix memory leak with large message
2 parents b2f1641 + 725c653 commit aab6d2e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

nsqd/protocol_v2.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ func (p *protocolV2) IOLoop(conn net.Conn) error {
120120
return err
121121
}
122122

123-
func (p *protocolV2) SendMessage(client *clientV2, msg *Message, buf *bytes.Buffer) error {
123+
func (p *protocolV2) SendMessage(client *clientV2, msg *Message) error {
124124
p.ctx.nsqd.logf(LOG_DEBUG, "PROTOCOL(V2): writing msg(%s) to client(%s) - %s", msg.ID, client, msg.Body)
125+
var buf = &bytes.Buffer{}
125126

126-
buf.Reset()
127127
_, err := msg.WriteTo(buf)
128128
if err != nil {
129129
return err
@@ -199,7 +199,6 @@ func (p *protocolV2) Exec(client *clientV2, params [][]byte) ([]byte, error) {
199199

200200
func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {
201201
var err error
202-
var buf bytes.Buffer
203202
var memoryMsgChan chan *Message
204203
var backendMsgChan chan []byte
205204
var subChannel *Channel
@@ -312,7 +311,7 @@ func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {
312311

313312
subChannel.StartInFlightTimeout(msg, client.ID, msgTimeout)
314313
client.SendingMessage()
315-
err = p.SendMessage(client, msg, &buf)
314+
err = p.SendMessage(client, msg)
316315
if err != nil {
317316
goto exit
318317
}
@@ -325,7 +324,7 @@ func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {
325324

326325
subChannel.StartInFlightTimeout(msg, client.ID, msgTimeout)
327326
client.SendingMessage()
328-
err = p.SendMessage(client, msg, &buf)
327+
err = p.SendMessage(client, msg)
329328
if err != nil {
330329
goto exit
331330
}

0 commit comments

Comments
 (0)