Skip to content

Commit

Permalink
Merge pull request #996 from andyxning/fix_memory_leak_with_large_mes…
Browse files Browse the repository at this point in the history
…sage

nsqd: fix memory leak with large message
  • Loading branch information
mreiferson authored Mar 6, 2018
2 parents b2f1641 + 725c653 commit aab6d2e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func (p *protocolV2) IOLoop(conn net.Conn) error {
return err
}

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

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

func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {
var err error
var buf bytes.Buffer
var memoryMsgChan chan *Message
var backendMsgChan chan []byte
var subChannel *Channel
Expand Down Expand Up @@ -312,7 +311,7 @@ func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {

subChannel.StartInFlightTimeout(msg, client.ID, msgTimeout)
client.SendingMessage()
err = p.SendMessage(client, msg, &buf)
err = p.SendMessage(client, msg)
if err != nil {
goto exit
}
Expand All @@ -325,7 +324,7 @@ func (p *protocolV2) messagePump(client *clientV2, startedChan chan bool) {

subChannel.StartInFlightTimeout(msg, client.ID, msgTimeout)
client.SendingMessage()
err = p.SendMessage(client, msg, &buf)
err = p.SendMessage(client, msg)
if err != nil {
goto exit
}
Expand Down

0 comments on commit aab6d2e

Please sign in to comment.