[python-sybase] SEGV on solaris when WANT_THREADS defined

Jon Dyte jon at totient.demon.co.uk
Thu, 6 Nov 2003 22:57:50 +0000


Hi

I'm using twisted 110 and the adbapi ConnectionPool class.
I have a small 'toy' script which starts up and runs three
of four queries under the twisted event loop, (which will actually do the 
query in a seperate thread.)

If I compile the Sybase module without the WANT_THREADS flag,
the script appears to work.
When compiled with the FLAG, it sometimes hangs or SEGV's.
I managed to get Sybase built with debug info and the stack trace is below.

I only compiled the Module with the flag set after reading that twisted would
defer the call to a thread, is it necessary.

Context: Python 2.3.2, solaris 5.6, sun compiler cc

dbx) where
current thread: t@5
  [1] netp_checkextfds(0x403d00, 0xef00506c, 0x29c340, 0x29c3a8, 0x403d00,
0x47798c), at 0xee85d1ec
  [2] netp_callback_poll(0x403d00, 0x1388, 0xef10716c, 0x2b659c, 0x1, 0x0),
at 0xee85a660
  [3] syb_net_callback(0x403d00, 0x1388, 0xef10716c, 0x2b659c, 0x0, 0x0), at
0xee85007c
  [4] np_ctx_wait(0x3ba860, 0x23e190, 0x1388, 0x0, 0xef1071d4, 0x0), at
0xee8d1658
  [5] com_async_poll(0x3ba860, 0x23e190, 0x1388, 0x5, 0x0, 0x0), at
0xee78609c
  [6] ct__api_connect_async(0x47e8b0, 0x0, 0xfffffff7, 0x0, 0x0, 0x0), at
0xee8a5ff0
  [7] ct_connect(0x47e8b0, 0x1eda5c, 0xfffffff7, 0x1eda48, 0x2a6584,
0x63745f63), at 0xee8a6278
=>[8] CS_CONNECTION_ct_connect(self = 0x4835c0, args = 0x3faad0), line 310
in "conn.c"
  [9] call_function(0xef107518, 0x3faad0, 0x12035c, 0x0, 0x1, 0x1), at
0x7df50
  [10] eval_frame(0x3c3880, 0x2a6574, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [11] fast_function(0x3f82f0, 0xef107780, 0x1, 0x405230, 0x2a6428,
0x480ef8), at 0x7e1a4
  [12] call_function(0xef107780, 0x47e87c, 0x480e90, 0x0, 0x1, 0x1), at
0x7e040
  [13] eval_frame(0x3c3810, 0x47e84c, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [14] PyEval_EvalCodeEx(0x3d4aa0, 0x9, 0x9, 0x0, 0x3f88bc, 0x0), at 0x7c944
  [15] function_call(0x3f81f0, 0x3f88b0, 0x0, 0x5, 0x3de2ac, 0x0), at
0xbc930
  [16] PyObject_Call(0x3f81f0, 0x3f88b0, 0x0, 0x19de60, 0x272, 0x1e), at
0x2b6ac
  [17] instancemethod_call(0x8, 0x3f88b0, 0x0, 0x3f6660, 0x3f81f0,
0x480e90), at 0x318fc
  [18] PyObject_Call(0x480a30, 0x1e3af0, 0x0, 0x480a30, 0x3de2dc, 0x233068),
at 0x2b6ac
  [19] PyEval_CallObjectWithKeywords(0x480a30, 0x1e3af0, 0x0, 0x0, 0x0,
0x1e3b1d), at 0x7dc38
  [20] PyInstance_New(0x152000, 0x1e3af0, 0x0, 0x480a30, 0x480e90,
0xef108144), at 0x2d7bc
  [21] PyObject_Call(0x3f6660, 0x1e3af0, 0x0, 0x2a9970, 0x3afcf8, 0x1a8), at
0x2b6ac
  [22] do_call(0x0, 0xef107f10, 0x8, 0x0, 0x3f6660, 0x0), at 0x7e5c4
  [23] call_function(0xef107f10, 0x2a6230, 0x62f8d952, 0x0, 0x8, 0x8), at
0x7e05c
  [24] eval_frame(0x3d64b0, 0x2a620c, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [25] PyEval_EvalCodeEx(0x3da060, 0x3de2dc, 0x14, 0x20, 0x5, 0x0), at
0x7c944
  [26] function_call(0x3f1730, 0x1e8300, 0x1, 0x5, 0x3de2dc, 0x233068), at
0xbc930
  [27] PyObject_Call(0x3f1730, 0x1e8300, 0x3cf390, 0x4805a4, 0x13c114, 0x3),
at 0x2b6ac
  [28] PyEval_CallObjectWithKeywords(0x3f1730, 0x1e8300, 0x3cf390, 0x3,
0xef108138, 0xef108144), at 0x7dc38
  [29] builtin_apply(0x0, 0x480af8, 0x0, 0x7019c, 0x0, 0x480b11), at 0x702fc
  [30] call_function(0xef108330, 0x480af8, 0x12035c, 0x0, 0x3, 0x3), at
0x7df50
  [31] eval_frame(0x1f01e0, 0x2a73a4, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [32] fast_function(0x2075b0, 0xef108598, 0x1, 0x405230, 0x2a7258, 0x8), at
0x7e1a4
  [33] call_function(0xef108598, 0x2a2bc0, 0x1f39e0, 0x0, 0x1, 0x1), at
0x7e040
  [34] eval_frame(0x18bf80, 0x2a2ba4, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [35] PyEval_EvalCodeEx(0x1ef7a0, 0x1, 0x2, 0x487ae0, 0x480564, 0x0), at
0x7c944
  [36] function_call(0x2078b0, 0x480558, 0x0, 0x0, 0x0, 0x233028), at
0xbc930
  [37] PyObject_Call(0x2078b0, 0x480558, 0x487150, 0xef1088e8, 0x2dc0f8,
0x2), at 0x2b6ac
  [38] ext_do_call(0x2078b0, 0x1, 0x3, 0x0, 0x480558, 0x487150), at 0x7e7f8
  [39] eval_frame(0x1f37b0, 0x2a71f4, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b4b4
  [40] PyEval_EvalCodeEx(0x1f41e0, 0x4, 0x4, 0x0, 0x4834ec, 0x0), at 0x7c944
  [41] function_call(0x1f45b0, 0x4834e0, 0x0, 0x0, 0x0, 0x233008), at
0xbc930
  [42] PyObject_Call(0x1f45b0, 0x4834e0, 0x4879c0, 0xef108c38, 0x480b20,
0x0), at 0x2b6ac
  [43] ext_do_call(0x1f45b0, 0x4, 0x3, 0x0, 0x4834e0, 0x4879c0), at 0x7e7f8
  [44] eval_frame(0x2141e8, 0x2a29d4, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b4b4
  [45] PyEval_EvalCodeEx(0x21fee0, 0x3, 0x7, 0x4879c0, 0x3f33f4, 0x0), at
0x7c944
  [46] function_call(0x2d0d70, 0x3f33e8, 0x0, 0x0, 0x0, 0x233018), at
0xbc930
  [47] PyObject_Call(0x2d0d70, 0x3f33e8, 0x487780, 0xef108f88, 0x2a2888,
0x8), at 0x2b6ac
  [48] ext_do_call(0x2d0d70, 0x4, 0x3, 0x0, 0x3f33e8, 0x487780), at 0x7e7f8
  [49] eval_frame(0x271030, 0x2a7044, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b4b4
  [50] PyEval_EvalCodeEx(0x2d0b20, 0x3, 0x7, 0x487780, 0x3f318c, 0x0), at
0x7c944
  [51] function_call(0x2d0e70, 0x3f3180, 0x0, 0x0, 0x0, 0x232ff8), at
0xbc930
  [52] PyObject_Call(0x2d0e70, 0x3f3180, 0x487300, 0xef1092d8, 0x2a6ef8,
0x8), at 0x2b6ac
  [53] ext_do_call(0x2d0e70, 0x4, 0x3, 0x0, 0x3f3180, 0x487300), at 0x7e7f8
  [54] eval_frame(0x1fbad0, 0x2a1824, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b4b4
  [55] PyEval_EvalCodeEx(0x3f8560, 0x2, 0x2, 0x0, 0x48049c, 0x0), at 0x7c944
  [56] function_call(0x481f70, 0x480490, 0x0, 0x0, 0x0, 0x232fe8), at
0xbc930
  [57] PyObject_Call(0x481f70, 0x480490, 0x3e2c00, 0xef109628, 0x13c114,
0x3), at 0x2b6ac
  [58] ext_do_call(0x481f70, 0x1, 0x3, 0x0, 0x480490, 0x3e2c00), at 0x7e7f8
  [59] eval_frame(0x3e3f50, 0x299874, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b4b4
  [60] fast_function(0x3f0eb0, 0xef109890, 0x1, 0x405230, 0x299728,
0x3e2afc), at 0x7e1a4
  [61] call_function(0xef109890, 0x2a4490, 0x3faa10, 0x0, 0x1, 0x1), at
0x7e040
  [62] eval_frame(0x3e6bf0, 0x2a4484, 0x1219a4, 0x13c120, 0x13c114, 0x0), at
0x7b34c
  [63] PyEval_EvalCodeEx(0x3e6d60, 0x1, 0x1, 0x0, 0x3faa5c, 0x0), at 0x7c944
  [64] function_call(0x3f0ef0, 0x3faa50, 0x0, 0x0, 0x0, 0x0), at 0xbc930
  [65] PyObject_Call(0x3f0ef0, 0x3faa50, 0x0, 0x534d, 0x2b0858, 0x2b0840),
at 0x2b6ac
  [66] instancemethod_call(0x0, 0x3faa50, 0x0, 0x40bdc8, 0x3f0ef0,
0x3faa10), at 0x318fc
  [67] PyObject_Call(0x480a08, 0x158030, 0x0, 0x0, 0x0, 0x0), at 0x2b6ac
  [68] PyEval_CallObjectWithKeywords(0x480a08, 0x158030, 0x0, 0x0, 0x0,
0x0), at 0x7dc38
  [69] t_bootstrap(0x234f28, 0x405230, 0x1, 0xef518340, 0x1, 0xef516bf0), at
0xa116c
(dbx)

the listing is 
the SEGV is line 310 in ct_connect.

(dbx) list 285 330
  285
  286   static PyObject *CS_CONNECTION_ct_connect(CS_CONNECTIONObj *self,
PyObject *args)
  287   {
  288       CS_RETCODE status;
  289       char *dsn = NULL;
  290
  291       if (!PyArg_ParseTuple(args, "|s", &dsn))
  292           return NULL;
  293
  294       if (self->conn == NULL) {
  295           PyErr_SetString(PyExc_TypeError, "CS_CONNECTION has been
dropped");
  296           return NULL;
  297       }
  298
  299       /* PyErr_Clear(); */
  300       if (dsn == NULL) {
  301           SY_CONN_BEGIN_THREADS(self);
  302           status = ct_connect(self->conn, NULL, 0);
  303           SY_CONN_END_THREADS(self);
  304
  305           if (self->debug)
  306               debug_msg("ct_connect(conn%d, NULL, 0) -> %s\n",
  307                         self->serial, value_str(VAL_STATUS, status));
  308       } else {
  309           SY_CONN_BEGIN_THREADS(self);
  310           status = ct_connect(self->conn, dsn, CS_NULLTERM);
  311           SY_CONN_END_THREADS(self);
  312
  313           if (self->debug)
  314               debug_msg("ct_connect(conn%d, \"%s\", CS_NULLTERM) ->
%s\n",
  315                         self->serial, dsn, value_str(VAL_STATUS,
status));
  316       }
  317       if (PyErr_Occurred())
  318           return NULL;
  319
  320       return PyInt_FromLong(status);
  321   }


some local variables are :-
(dbx) print status
status = 1
(dbx) print dsn
dsn = 0x1eda5c "SQL_MIDOFF_PDS1"
(dbx) print *self
*self = {
    ob_refcnt     = 4
    ob_type       = 0xee9cb3f0
    ctx           = 0x3c3f70
    conn          = 0x47e8b0
    strip         = 0
    debug         = 0
    serial        = 0
    lock          = (nil)
    thread_state  = 0x405230
    released_lock = 1
    reenter_count = 0
    next          = (nil)
}
(dbx) print *args
*args = {
    ob_refcnt = 1
    ob_type   = 0x12500c

Any ideas



Jon