hackinghat / cl-mysql

Common Lisp MySQL library
http://hackinghat.com/index.php/cl-mysql
53 stars 17 forks source link

unexpected behaviour with sb-thread. #7

Open rudolph-miller opened 9 years ago

rudolph-miller commented 9 years ago
(lisp-implementation-type)
;; => "SBCL"
(lisp-implementation-version)
;; => "1.2.13"

*features*
#|
=>
(:THREAD-SUPPORT CFFI-FEATURES:FLAT-NAMESPACE CFFI-FEATURES:X86-64
 CFFI-FEATURES:UNIX CFFI-FEATURES:DARWIN :CFFI CFFI-SYS::FLAT-NAMESPACE :SWANK
 :QLOT :CL-PPCRE :QUICKLISP :ROS.INIT :ASDF-PACKAGE-SYSTEM :ASDF3.1 :ASDF3
 :ASDF2 :ASDF :OS-MACOSX :OS-UNIX :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE
 :ALIEN-CALLBACKS :ANSI-CL :ASH-RIGHT-VOPS :BSD :C-STACK-IS-CONTROL-STACK
 :COMMON-LISP :COMPARE-AND-SWAP-VOPS :COMPLEX-FLOAT-VOPS :CYCLE-COUNTER :DARWIN
 :DARWIN9-OR-BETTER :FLOAT-EQL-VOPS :GENCGC :IEEE-FLOATING-POINT
 :INLINE-CONSTANTS :INODE64 :INTEGER-EQL-VOP :INTERLEAVED-RAW-SLOTS
 :LINKAGE-TABLE :LITTLE-ENDIAN :MACH-EXCEPTION-HANDLER :MACH-O
 :MEMORY-BARRIER-VOPS :MULTIPLY-HIGH-VOPS :OS-PROVIDES-BLKSIZE-T
 :OS-PROVIDES-DLADDR :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC
 :OS-PROVIDES-SUSECONDS-T :PACKAGE-LOCAL-NICKNAMES :PRECISE-ARG-COUNT-ERROR
 :RAW-INSTANCE-INIT-VOPS :SB-CORE-COMPRESSION :SB-DOC :SB-EVAL
 :SB-PACKAGE-LOCKS :SB-SIMD-PACK :SB-SOURCE-LOCATIONS :SB-TEST :SB-THREAD
 :SB-UNICODE :SBCL :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-FIXED-OBJECTS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-VECTORS
 :STACK-GROWS-DOWNWARD-NOT-UPWARD :SYMBOL-INFO-VOPS :UD2-BREAKPOINTS :UNIX
 :UNWIND-TO-FRAME-AND-CALL-VOP :X86-64)
|#

(ql:quickload '(:cl-mysql ))
(let ((thread (sb-thread:make-thread (lambda () (loop)))))
  (print (sb-thread:thread-alive-p thread))
  (sb-thread:destroy-thread thread)
  (sleep 1)
  (print (sb-thread:thread-alive-p thread)))
;; T
;; NIL

(cl-mysql:connect :database "test" :user "root")

(let ((thread (sb-thread:make-thread (lambda () (loop)))))
  (print (sb-thread:thread-alive-p thread))
  (sb-thread:destroy-thread thread)
  (sleep 1)
  (print (sb-thread:thread-alive-p thread)))
;; T
;; T

(ref https://github.com/fukamachi/clack/issues/118)

rudolph-miller commented 9 years ago

and I got an unexpected response when I GET http://hackinghat.com/. ;(

hackinghat commented 9 years ago

hackinghat.com is back up now apologies!

That's a strange problem you've found. I don't have a working system in-front of me at the moment but do you get the same problem if you don't use a busy loop?

rudolph-miller commented 9 years ago

I see.

That's not depends on what you do in the loop, and I think it's a issue of SBCL or CFFI.

I'll try more to inspect it.

rudolph-miller commented 9 years ago

It's actually not the issue of SBCL nor CFFI. MySQL blocks SIGPIPE on the first call of mysql_init. (ref https://dev.mysql.com/doc/refman/5.0/en/c-api-threaded-clients.html)

hackinghat commented 9 years ago

Good find!