File tree 3 files changed +18
-21
lines changed
3 files changed +18
-21
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,13 @@ import (
9
9
"github.com/koding/kite"
10
10
)
11
11
12
- func TestKite_SeparateKiteClient (t * testing.T ) {
12
+ func TestKite_MultipleDial (t * testing.T ) {
13
13
esrv := kite .New ("echo-server" , "0.0.0" )
14
14
esrv .Config .DisableAuthentication = true
15
+ if err := esrv .Config .ReadEnvironmentVariables (); err != nil {
16
+ t .Fatal (err )
17
+ }
18
+
15
19
esrv .HandleFunc ("echo" , func (r * kite.Request ) (interface {}, error ) {
16
20
var arg string
17
21
@@ -28,6 +32,9 @@ func TestKite_SeparateKiteClient(t *testing.T) {
28
32
29
33
ts := httptest .NewServer (esrv )
30
34
ecli := kite .New ("echo-client" , "0.0.0" )
35
+ if err := ecli .Config .ReadEnvironmentVariables (); err != nil {
36
+ t .Fatal (err )
37
+ }
31
38
32
39
esrv .SetLogLevel (kite .DEBUG )
33
40
ecli .SetLogLevel (kite .DEBUG )
@@ -38,6 +45,10 @@ func TestKite_SeparateKiteClient(t *testing.T) {
38
45
t .Fatalf ("dialing echo-server kite error: %s" , err )
39
46
}
40
47
48
+ if err := c .Dial (); err != nil {
49
+ t .Fatalf ("dialing echo-server kite error: %s" , err )
50
+ }
51
+
41
52
resp , err := c .Tell ("echo" , "Hello world!" )
42
53
if err != nil {
43
54
t .Fatalf ("Tell()=%s" , err )
Original file line number Diff line number Diff line change 1
1
package kite
2
2
3
3
import (
4
- "crypto/rand"
5
- "encoding/base64"
6
4
"encoding/json"
7
5
"errors"
8
6
"fmt"
@@ -304,14 +302,6 @@ func (c *Client) RemoteAddr() string {
304
302
return websocketsession .RemoteAddr ()
305
303
}
306
304
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
-
315
305
// run consumes incoming dnode messages. Reconnects if necessary.
316
306
func (c * Client ) run () {
317
307
err := c .readLoop ()
@@ -491,7 +481,7 @@ func (c *Client) sendHub() {
491
481
// And get rid of the timeout workaround.
492
482
c .LocalKite .Log .Error ("error sending %q: %s" , msg , err )
493
483
494
- if err == sockjsclient .ErrSessionClosed {
484
+ if err == sockjsclient .ErrSessionClosed || strings . Contains ( err . Error (), errClosing ) {
495
485
return
496
486
}
497
487
}
@@ -765,10 +755,6 @@ func (c *Client) getSession() sockjs.Session {
765
755
766
756
func (c * Client ) setSession (session sockjs.Session ) {
767
757
c .m .Lock ()
768
- if c .session != nil {
769
- c .session .Close (3000 , "Go away!" )
770
- }
771
-
772
758
c .session = session
773
759
c .m .Unlock ()
774
760
}
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ import (
13
13
"sync"
14
14
)
15
15
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
+
16
21
// Run is a blocking method. It runs the kite server and then accepts requests
17
22
// asynchronously. It supports graceful restart via SIGUSR2.
18
23
func (k * Kite ) Run () {
@@ -21,11 +26,6 @@ func (k *Kite) Run() {
21
26
os .Exit (0 )
22
27
}
23
28
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
-
29
29
err := k .listenAndServe ()
30
30
if err != nil {
31
31
if strings .Contains (err .Error (), errClosing ) {
You can’t perform that action at this time.
0 commit comments