From bba97134e983541e94cf73e93900729e3a3e61fc Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 28 Oct 2021 17:46:54 +0300 Subject: Moving request limit control to libunit. Introducting application graceful stop. For now only used when application process reach request limit value. This closes #585 issue on GitHub. --- go/port.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'go') diff --git a/go/port.go b/go/port.go index 78351322..388adc4a 100644 --- a/go/port.go +++ b/go/port.go @@ -120,7 +120,8 @@ func nxt_go_add_port(ctx *C.nxt_unit_ctx_t, p *C.nxt_unit_port_t) C.int { } //export nxt_go_remove_port -func nxt_go_remove_port(unit *C.nxt_unit_t, p *C.nxt_unit_port_t) { +func nxt_go_remove_port(unit *C.nxt_unit_t, ctx *C.nxt_unit_ctx_t, + p *C.nxt_unit_port_t) { key := port_key{ pid: int(p.id.pid), -- cgit From da0826e99f2c2144ea8e4b9a8b42f30ccf3203fa Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 8 Nov 2021 23:04:38 +0300 Subject: 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. --- go/nxt_cgo_lib.c | 1 + go/port.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'go') 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 } -- cgit From ff6a7053f500414dc74568a4e49adbac7f0cf634 Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Tue, 9 Nov 2021 15:48:44 +0300 Subject: Introduced SCM_CREDENTIALS / SCM_CREDS in the socket control msgs. --- go/nxt_cgo_lib.c | 8 ++++---- go/port.go | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'go') diff --git a/go/nxt_cgo_lib.c b/go/nxt_cgo_lib.c index 3e766b1e..ca9fc3ab 100644 --- a/go/nxt_cgo_lib.c +++ b/go/nxt_cgo_lib.c @@ -10,10 +10,10 @@ #include -static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *, nxt_unit_port_t *port, +static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, const void *buf, size_t buf_size, const void *oob, size_t oob_size); -static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *, nxt_unit_port_t *port, - void *buf, size_t buf_size, void *oob, size_t oob_size); +static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, + void *buf, size_t buf_size, void *oob, size_t *oob_size); int nxt_cgo_run(uintptr_t handler) @@ -58,7 +58,7 @@ nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port, - void *buf, size_t buf_size, void *oob, size_t oob_size) + void *buf, size_t buf_size, void *oob, size_t *oob_size) { return nxt_go_port_recv(port->id.pid, port->id.id, buf, buf_size, oob, oob_size); diff --git a/go/port.go b/go/port.go index 8fa94cb4..6635e87c 100644 --- a/go/port.go +++ b/go/port.go @@ -169,7 +169,7 @@ func nxt_go_port_send(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int, //export nxt_go_port_recv func nxt_go_port_recv(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int, - oob unsafe.Pointer, oob_size C.int) C.ssize_t { + oob unsafe.Pointer, oob_size *C.size_t) C.ssize_t { key := port_key{ pid: int(pid), @@ -184,7 +184,7 @@ func nxt_go_port_recv(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int, } n, oobn, _, _, err := p.rcv.ReadMsgUnix(GoBytes(buf, buf_size), - GoBytes(oob, oob_size)) + GoBytes(oob, C.int(*oob_size))) if err != nil { if nerr, ok := err.(*net.OpError); ok { @@ -196,6 +196,9 @@ func nxt_go_port_recv(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int, nxt_go_warn("read result %d (%d), %s", n, oobn, err) n = -1 + + } else { + *oob_size = C.size_t(oobn) } return C.ssize_t(n) -- cgit