Skip to content

Commit

Permalink
Fix channel block (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 authored Sep 8, 2021
1 parent c5955ae commit 2e3871f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/fagongzi/goetty/codec/simple"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -43,6 +44,19 @@ func TestStop(t *testing.T) {
assert.NoError(t, app.Stop())
}

func TestCloseBlock(t *testing.T) {
app := newTestTCPApp(t, nil).(*server)
assert.NoError(t, app.Start())

conn := newTestIOSession(t, WithEnableAsyncWrite(16), WithLogger(zap.NewExample()))
ok, err := conn.Connect(testAddr, time.Second)
assert.NoError(t, err)
assert.True(t, ok)
assert.NoError(t, app.Stop())
assert.NoError(t, conn.Write(string(make([]byte, 1024*1024))))
assert.NoError(t, conn.Close())
}

func newTestTCPApp(t *testing.T, handleFunc func(IOSession, interface{}, uint64) error, opts ...AppOption) NetApplication {
encoder, decoder := simple.NewStringCodec()
opts = append(opts, WithAppSessionOptions(WithCodec(encoder, decoder)))
Expand Down
3 changes: 1 addition & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ func (bio *baseIO) writeLoop(q queue.Queue) {

err = bio.Flush()
if err != nil {
bio.logger.Error("flush messages failed, closed this session", zap.Error(err))
return
bio.logger.Error("flush messages failed, closed this session", zap.Int32("state", bio.getState()), zap.Error(err))
}
}
}
Expand Down

0 comments on commit 2e3871f

Please sign in to comment.