StefanKopieczek / gossip

SIP stack in Golang
GNU Lesser General Public License v2.1
336 stars 109 forks source link

[Bug] Uninitialized timer, Sending Requests via TCP #9

Closed sushant-hiray closed 9 years ago

sushant-hiray commented 9 years ago

I was trying to run the INVITE tests on top of TCP as opposed to that of UDP. Here is a minor relevant log:

=== RUN TestAAAASetup
--- PASS: TestAAAASetup (0.00s)
=== RUN TestSendInviteTCP
DEBUG: Chan 0x1854430c gets '0'
DEBUG: Chan 0x1854430c sends '0'
DEBUG: Parser buffer returns line 'INVITE sip:user1@ims.hom SIP/2.0'
DEBUG: Parser buffer returns line 'Via: SIP/2.0/TCP 192.168.1.39:5060;branch=z9hG4bK776asdhds'
DEBUG: Parser buffer returns line ''
DEBUG: Parser 0x18544300 parsing header "Via: SIP/2.0/TCP 192.168.1.39:5060;branch=z9hG4bK776asdhds"
DEBUG: Parser buffer returns chunk ''
DEBUG: Stopping parser 0x18544300
DEBUG: Parser 0x18544300 stopped
DEBUG: Notifier 0x18536b20 has new listener 0x18544640
>>> DEBUG: Performing action &{0x18544480}
DEBUG: [manager::Send]Sending to 192.168.1.41:5060: INVITE sip:user1@ims.hom SIP/2.0
Via: SIP/2.0/TCP 192.168.1.39:5060;branch=z9hG4bK776asdhds

DEBUG: Query connection for address 192.168.1.41:5060 returns nil (no registered watcher)
DEBUG: No stored connection for address 192.168.1.41:5060; generate a new one
DEBUG: Parser 0x18544300 stopped
INFO: Begin serving TCP on address 192.168.1.39:5060
DEBUG: Chan 0x1854430c will dispose
DEBUG: Chan 0x1854430c disposing...
DEBUG: Chan 0x1854430c disposed
DEBUG: No connection watcher registered for 192.168.1.41:5060; spawn one
DEBUG: Connection 0x18536cc0 waiting for new data on sock
DEBUG: Stopping parser 0x18544880
DEBUG: Parser 0x18544880 stopped
panic: time: Stop called on uninitialized Timer

goroutine 16 [running]:
time.(*Timer).Stop(0x18538660, 0x18544900)
    /usr/local/go/src/time/sleep.go:59 +0x61
github.com/stefankopieczek/gossip/transport.func·002(0x18536d20)
    /home/ubuntu32/gossip/src/github.com/stefankopieczek/gossip/transport/conntable.go:66 +0x2fb
created by github.com/stefankopieczek/gossip/transport.(*connTable).Notify
    /home/ubuntu32/gossip/src/github.com/stefankopieczek/gossip/transport/conntable.go:79 +0x32a

Is the following function correct place to initialize the timer and fix the bug?

// Create a new connection table.
func (t *connTable) Init() {
    t.conns = make(map[string]*connWatcher)
}
rynorris commented 9 years ago

Thanks for spotting this.

That's not quite the right place. It's the timer on the connWatcher: watcher = &connWatcher{addr, conn, &time.Timer{}, make(chan *connection), make(chan bool)}

This is wrong, the &time.Timer{} needs changing into NewTimer(c_SOCKET_EXPIRY). I will make the fix soon.

rynorris commented 9 years ago

Should now be fixed by this commit

Please retest and confirm.

StefanKopieczek commented 9 years ago

Can we close this?

StefanKopieczek commented 9 years ago

Closing for now, will reopen if Sushant comes back to says there's still a problem here.