File tree Expand file tree Collapse file tree 3 files changed +18
-21
lines changed
Expand file tree Collapse file tree 3 files changed +18
-21
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,13 @@ import (
99 "github.com/koding/kite"
1010)
1111
12- func TestKite_SeparateKiteClient (t * testing.T ) {
12+ func TestKite_MultipleDial (t * testing.T ) {
1313 esrv := kite .New ("echo-server" , "0.0.0" )
1414 esrv .Config .DisableAuthentication = true
15+ if err := esrv .Config .ReadEnvironmentVariables (); err != nil {
16+ t .Fatal (err )
17+ }
18+
1519 esrv .HandleFunc ("echo" , func (r * kite.Request ) (interface {}, error ) {
1620 var arg string
1721
@@ -28,6 +32,9 @@ func TestKite_SeparateKiteClient(t *testing.T) {
2832
2933 ts := httptest .NewServer (esrv )
3034 ecli := kite .New ("echo-client" , "0.0.0" )
35+ if err := ecli .Config .ReadEnvironmentVariables (); err != nil {
36+ t .Fatal (err )
37+ }
3138
3239 esrv .SetLogLevel (kite .DEBUG )
3340 ecli .SetLogLevel (kite .DEBUG )
@@ -38,6 +45,10 @@ func TestKite_SeparateKiteClient(t *testing.T) {
3845 t .Fatalf ("dialing echo-server kite error: %s" , err )
3946 }
4047
48+ if err := c .Dial (); err != nil {
49+ t .Fatalf ("dialing echo-server kite error: %s" , err )
50+ }
51+
4152 resp , err := c .Tell ("echo" , "Hello world!" )
4253 if err != nil {
4354 t .Fatalf ("Tell()=%s" , err )
Original file line number Diff line number Diff line change 11package kite
22
33import (
4- "crypto/rand"
5- "encoding/base64"
64 "encoding/json"
75 "errors"
86 "fmt"
@@ -304,14 +302,6 @@ func (c *Client) RemoteAddr() string {
304302 return websocketsession .RemoteAddr ()
305303}
306304
307- // randomStringLength is used to generate a session_id.
308- func randomStringLength (length int ) string {
309- size := (length * 6 / 8 ) + 1
310- r := make ([]byte , size )
311- rand .Read (r )
312- return base64 .URLEncoding .EncodeToString (r )[:length ]
313- }
314-
315305// run consumes incoming dnode messages. Reconnects if necessary.
316306func (c * Client ) run () {
317307 err := c .readLoop ()
@@ -491,7 +481,7 @@ func (c *Client) sendHub() {
491481 // And get rid of the timeout workaround.
492482 c .LocalKite .Log .Error ("error sending %q: %s" , msg , err )
493483
494- if err == sockjsclient .ErrSessionClosed {
484+ if err == sockjsclient .ErrSessionClosed || strings . Contains ( err . Error (), errClosing ) {
495485 return
496486 }
497487 }
@@ -765,10 +755,6 @@ func (c *Client) getSession() sockjs.Session {
765755
766756func (c * Client ) setSession (session sockjs.Session ) {
767757 c .m .Lock ()
768- if c .session != nil {
769- c .session .Close (3000 , "Go away!" )
770- }
771-
772758 c .session = session
773759 c .m .Unlock ()
774760}
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ import (
1313 "sync"
1414)
1515
16+ // An error string equivalent to net.errClosing for using with http.Serve()
17+ // during a graceful exit. Needed to declare here again because it is not
18+ // exported by "net" package.
19+ const errClosing = "use of closed network connection"
20+
1621// Run is a blocking method. It runs the kite server and then accepts requests
1722// asynchronously. It supports graceful restart via SIGUSR2.
1823func (k * Kite ) Run () {
@@ -21,11 +26,6 @@ func (k *Kite) Run() {
2126 os .Exit (0 )
2227 }
2328
24- // An error string equivalent to net.errClosing for using with http.Serve()
25- // during a graceful exit. Needed to declare here again because it is not
26- // exported by "net" package.
27- const errClosing = "use of closed network connection"
28-
2929 err := k .listenAndServe ()
3030 if err != nil {
3131 if strings .Contains (err .Error (), errClosing ) {
You can’t perform that action at this time.
0 commit comments