summaryrefslogtreecommitdiffhomepage
path: root/go
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2021-11-08 23:04:38 +0300
committerMax Romanov <max.romanov@nginx.com>2021-11-08 23:04:38 +0300
commitda0826e99f2c2144ea8e4b9a8b42f30ccf3203fa (patch)
treebe2dd7f0f418ac2c723ba153ef4be917be52b939 /go
parent98c9763189728a17bef0a3ac1f421cb25678c018 (diff)
downloadunit-da0826e99f2c2144ea8e4b9a8b42f30ccf3203fa.tar.gz
unit-da0826e99f2c2144ea8e4b9a8b42f30ccf3203fa.tar.bz2
Go: fixing racing condition on app start.
Request procesing loop should be started in ready handler to avoid race between go-routine start and context ready flag assignment. The issue introduced in 43553aa72111.
Diffstat (limited to 'go')
-rw-r--r--go/nxt_cgo_lib.c1
-rw-r--r--go/port.go13
2 files changed, 9 insertions, 5 deletions
diff --git a/go/nxt_cgo_lib.c b/go/nxt_cgo_lib.c
index 330697c1..3e766b1e 100644
--- a/go/nxt_cgo_lib.c
+++ b/go/nxt_cgo_lib.c
@@ -30,6 +30,7 @@ nxt_cgo_run(uintptr_t handler)
init.callbacks.port_send = nxt_cgo_port_send;
init.callbacks.port_recv = nxt_cgo_port_recv;
init.callbacks.shm_ack_handler = nxt_go_shm_ack_handler;
+ init.callbacks.ready_handler = nxt_go_ready;
init.data = (void *) handler;
diff --git a/go/port.go b/go/port.go
index 388adc4a..8fa94cb4 100644
--- a/go/port.go
+++ b/go/port.go
@@ -110,11 +110,14 @@ func nxt_go_add_port(ctx *C.nxt_unit_ctx_t, p *C.nxt_unit_port_t) C.int {
p.in_fd = -1
p.out_fd = -1
- if new_port.key.id == 65535 {
- go func(ctx *C.nxt_unit_ctx_t) {
- C.nxt_unit_run_shared(ctx);
- }(ctx)
- }
+ return C.NXT_UNIT_OK
+}
+
+//export nxt_go_ready
+func nxt_go_ready(ctx *C.nxt_unit_ctx_t) C.int {
+ go func(ctx *C.nxt_unit_ctx_t) {
+ C.nxt_unit_run_shared(ctx)
+ }(ctx)
return C.NXT_UNIT_OK
}