Skip to content

Commit 33fce52

Browse files
committed
Fix nil pointer dereference in events.go handling node removal
For the moment we have unsafe coding where we try to use 'host' object before checking the success of it's 'get' operation. When a DB node gets forcibly terminated we have a race condition to get the following panic: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x632814] goroutine 1723 [running]: github.com/gocql/gocql.(*HostInfo).HostID(0xc0001500b8) %full-path%/host_source.go:253 +0x34 github.com/gocql/gocql.(*Session).handleRemovedNode( 0xc000150000, {0xc0134c10d8, 0xc0093d69b0, 0xa}, 0x45264d) %full-path%/events.go:243 +0x5f github.com/gocql/gocql.(*Session).handleNodeEvent( 0xc000150000, {0xc01701a000, 0x1, 0x43e305}) %full-path%/events.go:176 +0x28e created by github.com/gocql/gocql.(*eventDebouncer).flush %full-path%/events.go:67 +0xb5 So, fix it by checking the result first and only then use 'host' object.
1 parent e28a3ae commit 33fce52

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@ Ondrej Polakovič <[email protected]>
130130
Sergei Karetnikov <[email protected]>
131131
Stefan Miklosovic <[email protected]>
132132
Adam Burk <[email protected]>
133+
Valerii Ponomarov <[email protected]>

events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ func (s *Session) handleRemovedNode(ip net.IP, port int) {
240240

241241
// we remove all nodes but only add ones which pass the filter
242242
host, ok := s.ring.getHostByIP(ip.String())
243-
hostID := host.HostID()
244243
if ok {
244+
hostID := host.HostID()
245245
s.ring.removeHost(hostID)
246246

247247
host.setState(NodeDown)

0 commit comments

Comments
 (0)