good morning!!!!

Skip to content
Snippets Groups Projects
Commit 2bed11bf authored by Garet Halliday's avatar Garet Halliday
Browse files

idreply when closed

parent ffc8fc68
Branches
Tags
1 merge request!37return error to all clients waiting on idreply when connection closes
Pipeline #33432 passed
...@@ -29,8 +29,11 @@ func newClient(conn *websocket.Conn) (*Client, error) { ...@@ -29,8 +29,11 @@ func newClient(conn *websocket.Conn) (*Client, error) {
} }
func (c *Client) Close() error { func (c *Client) Close() error {
if err := c.Client.Close(); err != nil {
return err
}
if err := c.conn.Close(websocket.StatusNormalClosure, ""); err != nil { if err := c.conn.Close(websocket.StatusNormalClosure, ""); err != nil {
return err return err
} }
return c.Client.Close() return nil
} }
...@@ -173,7 +173,7 @@ func TestCloseClient(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestCloseClient(t *testing.T) {
} }
go func() { go func() {
if err := cl.Close(); err != nil { if err = cl.Close(); err != nil {
t.Error(err) t.Error(err)
} }
}() }()
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
type IdReply struct { type IdReply struct {
id atomic.Int64 id atomic.Int64
amClosed atomic.Bool close atomic.Bool
closed chan struct{} closed chan struct{}
chs map[string]chan msgOrError chs map[string]chan msgOrError
...@@ -109,7 +109,7 @@ func (i *IdReply) Closed() <-chan struct{} { ...@@ -109,7 +109,7 @@ func (i *IdReply) Closed() <-chan struct{} {
} }
func (i *IdReply) Close() error { func (i *IdReply) Close() error {
if i.amClosed.Swap(true) { if i.close.Swap(true) {
return net.ErrClosed return net.ErrClosed
} }
close(i.closed) close(i.closed)
......
...@@ -3,9 +3,7 @@ package jrpctest ...@@ -3,9 +3,7 @@ package jrpctest
import ( import (
"context" "context"
"embed" "embed"
"errors"
"math/rand" "math/rand"
"net"
"reflect" "reflect"
"sync" "sync"
"testing" "testing"
...@@ -190,16 +188,6 @@ func RunBasicTestSuite(t *testing.T, args BasicTestSuiteArgs) { ...@@ -190,16 +188,6 @@ func RunBasicTestSuite(t *testing.T, args BasicTestSuiteArgs) {
wg.Wait() wg.Wait()
}) })
makeTest("close", func(t *testing.T, server *server.Server, client jsonrpc.Conn) {
go func() {
_ = client.Close()
}()
err := jsonrpc.CallInto(context.Background(), client, nil, "test_block")
if !errors.Is(err, net.ErrClosed) {
t.Errorf("expected close error but got %v", err)
}
})
makeTest("", func(t *testing.T, server *server.Server, client jsonrpc.Conn) { makeTest("", func(t *testing.T, server *server.Server, client jsonrpc.Conn) {
}) })
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment