mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Fix memory leaks
This commit is contained in:
@@ -20,5 +20,7 @@ ADD . /gopath/src/github.com/buger/gor/
|
||||
|
||||
RUN javac -cp /tmp/commons-io-2.4/commons-io-2.4.jar ./examples/middleware/echo.java
|
||||
|
||||
RUN apt-get install graphviz -y
|
||||
|
||||
RUN go get -u github.com/golang/lint/golint
|
||||
RUN go get
|
||||
@@ -20,7 +20,7 @@ drace:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i --env GORACE="halt_on_error=1" gor go test ./... $(ARGS) -v -race -timeout 15s
|
||||
|
||||
dtest:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go test ./... $(ARGS) -v -timeout 60s
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go test ./... -timeout 5s $(ARGS) -v
|
||||
|
||||
dcover:
|
||||
docker run -v `pwd`:$(SOURCE_PATH) -t -i --env GORACE="halt_on_error=1" gor go test $(ARGS) -race -v -timeout 15s -coverprofile=coverage.out
|
||||
|
||||
@@ -257,4 +257,4 @@ func (t *Listener) Close() {
|
||||
close(t.quit)
|
||||
t.conn.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,6 @@ func NewTCPMessage(ID string, delChan chan *TCPMessage, Ack uint32, expire *time
|
||||
msg.Start = time.Now().UnixNano()
|
||||
msg.packetsChan = make(chan *TCPPacket)
|
||||
msg.delChan = delChan // used for notifying that message completed or expired
|
||||
msg.timer = time.NewTimer(0)
|
||||
|
||||
go msg.listen()
|
||||
|
||||
@@ -69,6 +68,10 @@ func (t *TCPMessage) listen() {
|
||||
|
||||
// Timeout notifies message to stop listening, close channel and message ready to be sent
|
||||
func (t *TCPMessage) Timeout() {
|
||||
if t.timer != nil {
|
||||
t.timer.Stop()
|
||||
}
|
||||
|
||||
select {
|
||||
// In some cases Timeout can be called multiple times (do not know how yet)
|
||||
// Ensure that we did not close channel 2 times
|
||||
@@ -139,12 +142,14 @@ func (t *TCPMessage) AddPacket(packet *TCPPacket) {
|
||||
t.Timeout()
|
||||
} else {
|
||||
// If more then 1 packet, wait for more, and set expiration
|
||||
if len(t.packets) == 1 {
|
||||
if len(t.packets) > 1 {
|
||||
// Every time we receive packet we reset this timer
|
||||
t.timer = time.AfterFunc(*t.expire, t.Timeout)
|
||||
} else {
|
||||
// Reset message timeout timer
|
||||
t.timer.Reset(*t.expire)
|
||||
if t.timer != nil {
|
||||
t.timer.Reset(*t.expire)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user