starting a swank server segfaults when core files are used

Bug #444427 reported by Attila Lendvai
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Slime
Fix Released
Undecided
Unassigned

Bug Description

a memory fault reliably happens when a swank server is started when sbcl was loaded from a previously saved core file, which had swank initialized.

Nikodemus identified the issue:

I'm thinking you're holding on to a live stream from a previous invocation, and then trying to write to the mmap'ed stream buffer which doesn't exist anymore.

Looking at SIMPLE-ANNOUNCE-FUNCTION, it writes to *LOG-OUTPUT*, which is conditionally initialized in INIT-LOG-OUTPUT. If you accidentally initialize it before saving the core, bad things are bound to happen.

a possible fix:

(in-package :swank)

(defun after-saved-image-initialized ()
  (setf *log-output* nil)
  (init-log-output))

#+sbcl(pushnew 'after-saved-image-initialized sb-ext:*init-hooks*)

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

Is the fault address deterministic?

I'm OK with the tarball.

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

HA! I have a guess.

I'm thinking you're holding on to a live stream from a previous invocation, and then trying to write to the mmap'ed stream buffer which doesn't exist anymore.

Looking at SIMPLE-ANNOUNCE-FUNCTION, it writes to *LOG-OUTPUT*, which is conditionally initialized in INIT-LOG-OUTPUT. If you accidentally initialize it before saving the core, bad things are bound to happen.

Try this:

(defun deinit-swank ()
  ;; Dunno if you need to do anything else?
  (setf swank:*log-output* nil))

(push 'deinit-swank *save-hooks*)

Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

brilliant remote debugging skills there Nikodemus!

when i started the image, and i simply

(setf swank:*log-output* nil)

then starting the server works fine!

i think this is a slime bug, or at least a deficiency... but on the other hand, if there's any chance for it, then a better error message from SBCL would be great!

thanks again!

Changed in sbcl:
status: New → Invalid
Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

for the record, putting this somewhere in swank.lisp fixes the issue:

(defun after-saved-image-initialized ()
  (setf *log-output* nil)
  (init-log-output))

#+sbcl(pushnew 'after-saved-image-initialized sb-ext:*init-hooks*)

Revision history for this message
Attila Lendvai (attila-lendvai) wrote :

i'm changing it to be a slime bug.

affects: sbcl → slime
Changed in slime:
status: Invalid → New
description: updated
summary: - reproducible memory fault from SB-IMPL::OUTPUT-BYTES/UTF-8
+ starting a swank server segfaults when core files are used
Changed in slime:
status: New → Fix Committed
Revision history for this message
Tobias C. Rittweiler (tcr) wrote :

Fixed in Slime 2010-10-08. Fix for SBCL only.

Revision history for this message
R. Matthew Emerson (rme) wrote :

CCL could use a similar fix.

 ccl:*save-exit-functions* is where one would push the function to reset *log-output*.

Revision history for this message
Stas Boukarev (stassats) wrote :

CCL has now the same fix.

Stas Boukarev (stassats)
Changed in slime:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.