This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: segfault in FreeBSD
Type: Stage:
Components: Extension Modules Versions: Python 2.4
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: aix-d, nnorwitz, uyamba
Priority: normal Keywords:

Created on 2006-02-11 08:16 by aix-d, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg27485 - (view) Author: aix-d (aix-d) Date: 2006-02-11 08:16
Dear developers,

My program has many TCP connections (~30 per second),
MySQL connections (~100 per second) and threads (~280).
It works long time and receives this segmentation fault:

exited on signal 11 (core dumped)

=========== GDB OUTPUT
=================================================
Program received signal SIGSEGV, Segmentation fault.
0x283199e8 in ?? () from
/usr/local/lib/python2.4/lib-dynload/_socket.so
(gdb) backtrace
#0  0x283199e8 in ?? () from
/usr/local/lib/python2.4/lib-dynload/_socket.so
#1  0x2831b3d5 in internal_connect ()
   from /usr/local/lib/python2.4/lib-dynload/_socket.so
#2  0x2831b440 in sock_connect ()
   from /usr/local/lib/python2.4/lib-dynload/_socket.so
#3  0x0805a828 in PyObject_Call ()
#4  0x080a01dd in PyEval_EvalFrame ()
#5  0x080a294f in PyEval_EvalCodeEx ()
#6  0x080a138b in PyEval_EvalFrame ()
#7  0x080a212d in PyEval_EvalFrame ()
#8  0x080a212d in PyEval_EvalFrame ()
#9  0x080a212d in PyEval_EvalFrame ()
#10 0x080a212d in PyEval_EvalFrame ()
#11 0x080a212d in PyEval_EvalFrame ()
#12 0x080a294f in PyEval_EvalCodeEx ()
#13 0x080a138b in PyEval_EvalFrame ()
#14 0x080a212d in PyEval_EvalFrame ()
#15 0x080a294f in PyEval_EvalCodeEx ()
#16 0x080da027 in PyFunction_SetClosure ()
#17 0x0805a828 in PyObject_Call ()
#18 0x080a01dd in PyEval_EvalFrame ()
#19 0x080a294f in PyEval_EvalCodeEx ()
#20 0x080a138b in PyEval_EvalFrame ()
#21 0x080a294f in PyEval_EvalCodeEx ()
#22 0x080a138b in PyEval_EvalFrame ()
#23 0x080a294f in PyEval_EvalCodeEx ()
#24 0x080a138b in PyEval_EvalFrame ()
#25 0x080a294f in PyEval_EvalCodeEx ()
#26 0x080a138b in PyEval_EvalFrame ()
#27 0x080a294f in PyEval_EvalCodeEx ()
#28 0x080a138b in PyEval_EvalFrame ()
#29 0x080a294f in PyEval_EvalCodeEx ()
#30 0x080a138b in PyEval_EvalFrame ()
#31 0x080a212d in PyEval_EvalFrame ()
#32 0x080a294f in PyEval_EvalCodeEx ()
#33 0x080da027 in PyFunction_SetClosure ()
#34 0x0805a828 in PyObject_Call ()
#35 0x080601e9 in PyMethod_New ()
#36 0x0805a828 in PyObject_Call ()
#37 0x0809cd31 in PyEval_CallObjectWithKeywords ()
#38 0x080c21a5 in _PyObject_GC_Del ()
#39 0x2821e0cc in pthread_create () from
/usr/lib/libpthread.so.2
#40 0x282db757 in _ctx_start () from /lib/libc.so.6
(gdb)
==== END OF GDB OUTPUT
=================================================

Imported modules: socket, atexit, time, pickle, os,
random, traceback, MySQLdb, re, urllib, urllib2, threading

Python version: 2.4.2

Operating system: FreeBSD 6.0-STABLE

Can you help with debugging?

Best regards, Alexander.
msg27486 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-12 06:54
Logged In: YES 
user_id=33168

Can you build python from source?  You can try checking out
the current 2.4 SVN.  This problem may have been fixed
recently.  I'm guessing that the socket descriptor value is
larger than FD_SETSIZE (probably 1k or 4k).  You also may
want to build python with debugging.

If that doesn't solve your problem, you will need to provide
more information about how to reproduce your problem.
msg27487 - (view) Author: Uyamba (uyamba) Date: 2006-02-12 16:47
Logged In: YES 
user_id=1450360

This is test program that generates fault:
----------------------------
#!/usr/local/bin/python

import socket, time
from threading import Thread

class cthread(Thread):
        def __init__ (self):
                Thread.__init__(self)

        def run(self):
                socket.setdefaulttimeout(5)
                res = socket.getaddrinfo('19.54.123.2', 33, 
0, socket.SOCK_STREAM)[0]
                sock = socket.socket(res[0], res[1], res[2])
                try:
                        sock.connect(res[4])
                except: pass

def main():
        for i in range(1900):
                print "starting " + str(i)
                ct = cthread()
                ct.start()

if __name__ == '__main__':
        main()

----------------------------
IP 19.54.123.2 is random. Results are various for some IPs 
and hostnames.
msg27488 - (view) Author: Uyamba (uyamba) Date: 2006-02-12 17:48
Logged In: YES 
user_id=1450360

This is detailed backtrace (from python compiled with 
CFLAGS+="-g"):
======================================
#0  0xa8348959 in ?? ()
#1  0x08ebb800 in ?? ()
#2  0x00000001 in ?? ()
#3  0x77881688 in ?? ()
#4  0x28348947 in internal_connect (s=0x8ebb800, 
addr=0x8ebb818, addrlen=16,
    timeoutp=0x778816b4)
    at /usr/ports/lang/python/work/Python-2.4.2/Modules/
socketmodule.c:1740
#5  0x28348a00 in sock_connect (s=0x8ebb800, 
addro=0x8ebd72c)
    at /usr/ports/lang/python/work/Python-2.4.2/Modules/
socketmodule.c:1771
======================================

This is the /usr/ports/lang/python/work/Python-2.4.2/
Modules/socketmodule.c:
======================================
        if (s->sock_timeout > 0.0) {
1740:           if (res < 0 && errno == EINPROGRESS) {
                        timeout = internal_select(s, 1);
                        res = connect(s->sock_fd, addr, 
addrlen);
                        if (res < 0 && errno == EISCONN)
                                res = 0;
                }
        }
======================================

No ideas :-(
msg27489 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-12 20:54
Logged In: YES 
user_id=33168

Can you "print *s" ?  My guess is that s->sock_fd >
FD_SETSIZE on your box.  I will try your test code with the
current versions and see if they still fail.
msg27490 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-12 21:09
Logged In: YES 
user_id=33168

I get exceptions when running normally. I had to do ulimit
-n 2000 to be able to run without exception.

I can confirm that with an unpatched 2.4.2, python crashed.
 With the 2.4.2+ patch, no crash.  On SVN head (2.5), I
didn't get a crash, but got a thread exception.  I think
this bug may be fixed.  To get the new features, you need to
update at least these files:

http://svn.python.org/projects/python/branches/release24-maint/Modules/socketmodule.c
http://svn.python.org/projects/python/branches/release24-maint/Modules/_ssl.c
http://svn.python.org/projects/python/branches/release24-maint/PC/pyconfig.h

Please verify if this is fixed for you.
msg27491 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-12 21:11
Logged In: YES 
user_id=33168

The 2.4 fix was committed in revision 42339.
msg27492 - (view) Author: Uyamba (uyamba) Date: 2006-02-12 23:14
Logged In: YES 
user_id=1450360

Thank you very much!!! :-)
It works fine: python-devel from FreeBSD ports with three 
files updated by SVN to latest version. But i can't compile 
full last SVN release on FreeBSD :-( Could you help with 
updating FreeBSD port please.
msg27493 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-02-12 23:20
Logged In: YES 
user_id=33168

Closing this bug report since it's fixed.

As to python not compiling on FreeBSD, open a new bug report
with all the info about what is causing the failure.  It
would be great if you can help diagnose the problem as not
many python developers have access to FreeBSD.  Is the
FreeBSD port up-to-date?
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42887
2006-02-11 08:16:57aix-dcreate