Skip to content

Commit

Permalink
Save/Restore the last used endpoint ids to avoid collisions.
Browse files Browse the repository at this point in the history
Endpoint ids are assigned in increasing order, and used to avoid deadlocks when
acquiring locks.  Previously, we were not saving the last used endpoint id, so
the ids would always start at 0 again after a Restore, which could lead to
collisions with existing endpoints.

This CL makes lastID a global, and each connectionedEndpoint saves/loads it.
It is a bit redundant to have each connectiondEndpoint do this work, but the
value of lastID will be the same for each, so it shouldn't hurt.  If there are
no saved connectionedEndpoints, then starting the counter over again at 0 makes
no difference.

PiperOrigin-RevId: 148900024
  • Loading branch information
nlacasse authored and crawshaw committed May 17, 2017
1 parent 90bf235 commit 44b744d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions tcpip/transport/unix/connectioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (
"github.com/google/netstack/waiter"
)

// lastID is the last endpoint id issued by UniqueID. It must be accessed
// atomically.
var lastID uint64

// UniqueID is used to generate endpoint ids.
var UniqueID = func() func() uint64 {
var id uint64
return func() uint64 {
return atomic.AddUint64(&id, 1)
}
}()
func UniqueID() uint64 {
return atomic.AddUint64(&lastID, 1)
}

// A ConnectingEndpoint is a connectioned unix endpoint that is attempting to
// connect to a ConnectionedEndpoint.
Expand Down Expand Up @@ -94,7 +95,7 @@ type connectionedEndpoint struct {
// have another associated connectionedEndpoint.
//
// If nil, then no listen call has been made.
acceptedChan chan *connectionedEndpoint `state:"manual"`
acceptedChan chan *connectionedEndpoint
}

// NewConnectioned creates a new unbound connectionedEndpoint.
Expand Down
2 changes: 1 addition & 1 deletion tcpip/transport/unix/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ type baseEndpoint struct {
path string

// isBound returns true iff the endpoint is bound.
isBound func() bool `state:"manual"`
isBound func() bool
}

// EventRegister implements waiter.Waitable.EventRegister.
Expand Down

0 comments on commit 44b744d

Please sign in to comment.