Skip to content

Commit 9017f69

Browse files
authored
Fix issues 89 and 87 (#91)
1 parent 7307b1d commit 9017f69

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

gen/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func (gs *Server) ProcessLoop(ps ProcessState, started chan<- bool) string {
279279
case direct := <-channels.Direct:
280280
gsp.waitCallbackOrDeferr(direct)
281281
continue
282+
case gsp.waitReply = <-gsp.callbackWaitReply:
283+
continue
282284
}
283285

284286
lib.Log("[%s] GEN_SERVER %s got message from %s", gsp.NodeName(), gsp.Self(), fromPid)

node/epmd.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ func (e *epmd) Init(ctx context.Context, name string, port uint16, opts Options)
8989
// trying to start embedded EPMD before we go further
9090
Server(ctx, e.Port)
9191
}
92+
dialer := net.Dialer{
93+
KeepAlive: 15 * time.Second,
94+
}
9295
dsn := net.JoinHostPort("", strconv.Itoa(int(e.Port)))
93-
conn, err := net.Dial("tcp", dsn)
96+
conn, err := dialer.Dial("tcp", dsn)
9497
if err != nil {
9598
ready <- err
9699
return

tests/server_test.go

+76
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,82 @@ func (gs *messageOrderGS) HandleDirect(process *gen.ServerProcess, message inter
409409
return nil, fmt.Errorf("incorrect direct call")
410410
}
411411

412+
type GSCallPanic struct {
413+
gen.Server
414+
}
415+
416+
func (gs *GSCallPanic) Init(process *gen.ServerProcess, args ...etf.Term) error {
417+
return nil
418+
}
419+
420+
func (gs *GSCallPanic) HandleCall(process *gen.ServerProcess, from gen.ServerFrom, message etf.Term) (etf.Term, gen.ServerStatus) {
421+
m := message.(string)
422+
if m == "panic" {
423+
panic("test")
424+
}
425+
426+
return "ok", gen.ServerStatusOK
427+
}
428+
429+
func (gs *GSCallPanic) HandleDirect(process *gen.ServerProcess, message interface{}) (interface{}, error) {
430+
431+
pids, ok := message.([]etf.Pid)
432+
if !ok {
433+
return nil, fmt.Errorf("not a pid")
434+
}
435+
if _, err := process.CallWithTimeout(pids[0], "panic", 1); err == nil {
436+
return nil, fmt.Errorf("must be error here")
437+
}
438+
439+
v, err := process.Call(pids[1], "test")
440+
if err != nil {
441+
return nil, err
442+
}
443+
if v.(string) != "ok" {
444+
return nil, fmt.Errorf("wrong result %#v", v)
445+
}
446+
447+
return nil, nil
448+
}
449+
450+
func TestServerCallServerWithPanic(t *testing.T) {
451+
fmt.Printf("\n=== Test Server. Making a Call to Server with panic (issue 86) \n")
452+
fmt.Printf("Starting node: nodeGSCallWithPanic1@localhost: ")
453+
node1, err1 := ergo.StartNode("nodeGSCallWithPanic1@localhost", "cookies", node.Options{})
454+
if err1 != nil {
455+
t.Fatal("can't start node", err1)
456+
} else {
457+
fmt.Println("OK")
458+
}
459+
fmt.Printf("Starting node: nodeGSCallWithPanic2@localhost: ")
460+
node2, err2 := ergo.StartNode("nodeGSCallWithPanic2@localhost", "cookies", node.Options{})
461+
if err2 != nil {
462+
t.Fatal("can't start node", err2)
463+
} else {
464+
fmt.Println("OK")
465+
}
466+
467+
p1n1, err := node1.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
468+
if err != nil {
469+
t.Fatal(err)
470+
}
471+
p1n2, err := node2.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
472+
if err != nil {
473+
t.Fatal(err)
474+
}
475+
p2n2, err := node2.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
476+
if err != nil {
477+
t.Fatal(err)
478+
}
479+
480+
pids := []etf.Pid{p1n2.Self(), p2n2.Self()}
481+
482+
if _, err := p1n1.Direct(pids); err != nil {
483+
t.Fatal(err)
484+
}
485+
fmt.Println("OK")
486+
}
487+
412488
func TestServerMessageOrder(t *testing.T) {
413489
fmt.Printf("\n=== Test Server message order\n")
414490
fmt.Printf("Starting node: nodeGS1MessageOrder@localhost: ")

0 commit comments

Comments
 (0)