Skip to content

Commit

Permalink
Merge pull request #54 from jbenet/sync-stream-creation
Browse files Browse the repository at this point in the history
synchronize stream creation
  • Loading branch information
dmcgowan committed Jun 15, 2015
2 parents e372247 + f8ff317 commit b2c3287
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ func (s *Connection) remoteStreamFinish(stream *Stream) {
// the stream Wait or WaitTimeout function on the stream returned
// by this function.
func (s *Connection) CreateStream(headers http.Header, parent *Stream, fin bool) (*Stream, error) {
// MUST synchronize stream creation (all the way to writing the frame)
// as stream IDs **MUST** increase monotonically.
s.nextIdLock.Lock()
defer s.nextIdLock.Unlock()

streamId := s.getNextStreamId()
if streamId == 0 {
return nil, fmt.Errorf("Unable to get new stream id")
Expand Down Expand Up @@ -833,8 +838,6 @@ func (s *Connection) sendStream(stream *Stream, fin bool) error {
// getNextStreamId returns the next sequential id
// every call should produce a unique value or an error
func (s *Connection) getNextStreamId() spdy.StreamId {
s.nextIdLock.Lock()
defer s.nextIdLock.Unlock()
sid := s.nextStreamId
if sid > 0x7fffffff {
return 0
Expand Down

0 comments on commit b2c3287

Please sign in to comment.