Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Python error: GC object already tracked #107

Closed
urba1n opened this issue Apr 19, 2018 · 3 comments
Closed

Fatal Python error: GC object already tracked #107

urba1n opened this issue Apr 19, 2018 · 3 comments

Comments

@urba1n
Copy link

urba1n commented Apr 19, 2018

Unit-Python with New Relic raises the following errors which prevent the application from running:
Apr 19 08:08:31 unit_as - Fatal Python error: GC object already tracked Apr 19 08:08:32 unit_as - 2018/04/19 08:08:31 [alert] 1#1 process 18 exited on signal 6 (core dumped) Apr 19 08:08:32 unit_as - 2018/04/19 08:08:31 [info] 17#39 *11 shutdown(50, 2) failed (107: Transport endpoint is not connected) Apr 19 08:08:32 unit_as - 2018/04/19 08:08:31 [info] 50#50 "unit-1|18-04-2018|17:33:54" application started Apr 19 08:08:32 unit_as - Fatal Python error: GC object already tracked Apr 19 08:08:32 unit_as - 2018/04/19 08:08:32 [alert] 1#1 process 23 exited on signal 6 (core dumped) Apr 19 08:08:32 unit_as - 2018/04/19 08:08:32 [info] 17#39 *26 shutdown(51, 2) failed (107: Transport endpoint is not connected) Apr 19 08:08:32 unit_as - 2018/04/19 08:08:32 [info] 55#55 "unit-1|18-04-2018|17:33:54" application started Apr 19 08:08:33 unit_as - 2018/04/19 08:08:33 [notice] 50#50 signal signo:17 (SIGCHLD) recevied, ignored

@VBart
Copy link
Contributor

VBart commented Apr 19, 2018

Thank you for the report. Could you please try the following patch in order to check if it fixes the issue?

# HG changeset patch
# User Alexander Borisov <alexander.borisov@nginx.com>
# Date 1524135711 -10800
#      Thu Apr 19 14:01:51 2018 +0300
# Node ID 588c2c58fe7ea06b3130d933e61df4abd8736a6d
# Parent  44f8dcca7f5860a9544a19bbf28c7bf2682cce4a
Python: returning write() callable object from start_respose().

According to PEP (3)333 the start_respose() function must return a write() callable.

diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -69,6 +69,7 @@ static PyObject *nxt_python_get_environ(
                       nxt_app_rmsg_t *rmsg, nxt_python_run_ctx_t *ctx);
 
 static PyObject *nxt_py_start_resp(PyObject *self, PyObject *args);
+static PyObject *nxt_py_write(PyObject *self, PyObject *args);
 
 static void nxt_py_input_dealloc(nxt_py_input_t *self);
 static PyObject *nxt_py_input_read(nxt_py_input_t *self, PyObject *args);
@@ -112,6 +113,11 @@ static PyMethodDef nxt_py_start_resp_met
 };
 
 
+static PyMethodDef nxt_py_write_method[] = {
+    {"unit_write", nxt_py_write, METH_O, ""}
+};
+
+
 static PyMethodDef nxt_py_input_methods[] = {
     { "read",      (PyCFunction) nxt_py_input_read,      METH_VARARGS, 0 },
     { "readline",  (PyCFunction) nxt_py_input_readline,  METH_VARARGS, 0 },
@@ -176,6 +182,7 @@ static PyTypeObject nxt_py_input_type = 
 
 static PyObject           *nxt_py_application;
 static PyObject           *nxt_py_start_resp_obj;
+static PyObject           *nxt_py_write_obj;
 static PyObject           *nxt_py_environ_ptyp;
 
 #if PY_MAJOR_VERSION == 3
@@ -263,6 +270,15 @@ nxt_python_init(nxt_task_t *task, nxt_co
 
     nxt_py_start_resp_obj = obj;
 
+    obj = PyCFunction_New(nxt_py_write_method, NULL);
+
+    if (nxt_slow_path(obj == NULL)) {
+        nxt_alert(task, "Python failed to initialize the \"write\" function");
+        goto fail;
+    }
+
+    nxt_py_write_obj = obj;
+
     obj = nxt_python_create_environ(task);
 
     if (obj == NULL) {
@@ -456,6 +472,7 @@ nxt_python_atexit(nxt_task_t *task)
 {
     Py_DECREF(nxt_py_application);
     Py_DECREF(nxt_py_start_resp_obj);
+    Py_DECREF(nxt_py_write_obj);
     Py_DECREF(nxt_py_environ_ptyp);
 
     Py_Finalize();
@@ -845,7 +862,36 @@ nxt_py_start_resp(PyObject *self, PyObje
     /* flush headers */
     nxt_python_write(ctx, cr_lf, sizeof(cr_lf) - 1, 1, 0);
 
-    return args;
+    Py_INCREF(nxt_py_write_obj);
+    return nxt_py_write_obj;
+}
+
+
+static PyObject *
+nxt_py_write(PyObject *self, PyObject *str)
+{
+    nxt_int_t  rc;
+
+    if (nxt_fast_path(!PyBytes_Check(str))) {
+#if PY_MAJOR_VERSION == 3
+        return PyErr_Format(PyExc_TypeError,
+                            "the argument is not a bytestring");
+#else
+        return PyErr_Format(PyExc_TypeError, "the argument is not a string");
+#endif
+    }
+
+    rc = nxt_app_msg_write_raw(nxt_python_run_ctx->task,
+                               nxt_python_run_ctx->wmsg,
+                               (const u_char *) PyBytes_AS_STRING(str),
+                               PyBytes_GET_SIZE(str));
+
+    if (nxt_slow_path(rc != NXT_OK)) {
+        return PyErr_Format(PyExc_RuntimeError,
+                            "failed to write response value");
+    }
+
+    Py_RETURN_NONE;
 }
 

@urba1n
Copy link
Author

urba1n commented Apr 19, 2018

With this patch the issue is fixed. Thank you very much!

@urba1n
Copy link
Author

urba1n commented Apr 19, 2018

While the applications is now working with New Relic, I get the following errors in the log at each service call:
Apr 19 16:29:48 unit_as - 2018/04/19 16:29:48 [info] 16#66 *199 shutdown(14, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:48 unit_as - 2018/04/19 16:29:48 [info] 16#44 *160 shutdown(14, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:48 unit_as - 2018/04/19 16:29:48 [info] 16#64 *202 shutdown(15, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:48 unit_as - 2018/04/19 16:29:48 [info] 16#69 *203 shutdown(14, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:49 unit_as - 2018/04/19 16:29:49 [info] 16#71 *211 shutdown(15, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:49 unit_as - 2018/04/19 16:29:49 [info] 16#68 *206 shutdown(15, 2) failed (107: Transport endpoint is not connected)
Apr 19 16:29:49 unit_as - 2018/04/19 16:29:49 [info] 16#71 *205 shutdown(14, 2) failed (107: Transport endpoint is not connected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants