You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SBCL生成Hunchentoot服务器可执行文件后访问崩溃问题排查

使用SBCL + Hunchentoot生成可执行HTTP服务器时访问崩溃的问题

我尝试用SBCL搭配Hunchentoot创建HTTP服务器,在REPL中测试或直接运行脚本文件时一切正常,但将核心保存为可执行文件后,每次访问服务器网页都会导致进程崩溃。

测试代码

我的测试代码保存在server.lisp文件中:

#!/usr/local/bin/sbcl --script

(require :asdf)
(asdf:load-system :hunchentoot)

(defpackage :http-server
  (:use :cl :hunchentoot))

(in-package :http-server)

(defvar *my-acceptor* (make-instance 'easy-acceptor :port 6161))

(defun main ()
  (format t "Starting http server on port ~a~%" (acceptor-port *my-acceptor*))
  (start *my-acceptor*)
  (handler-case
      (loop do (sleep 1000))
    (condition () nil)))

(defun hello ()
  (format nil "Hello, it works!"))

(push
 (create-prefix-dispatcher "/hello.html" #'hello)
 *dispatch-table*)

;; (sb-ext:save-lisp-and-die "http-server" :toplevel 'main :executable t)
(main)

直接运行该脚本时,服务器正常启动,http://127.0.0.1:6161/hello.html可正常访问。

之后我修改文件最后两行,尝试生成可执行文件:

(sb-ext:save-lisp-and-die "http-server" :toplevel 'main :executable t)
;; (main)

崩溃现象

运行修改后的脚本生成http-server可执行文件,启动该文件后,服务器看似正常启动,但每次访问http://127.0.0.1:6161/hello.html时,进程就会崩溃,报错如下:

Starting http server on port 6161
CORRUPTION WARNING in SBCL pid 206086 tid 206091:
Memory fault at 0x7f9c7c58b000 (pc=0x53617132 [code 0x53616f20+0x212 ID 0x43a3], fp=0x7f696af2dbc0, sp=0x7f696af2db68) tid 206091
The integrity of this image is possibly compromised.
Continuing with fingers crossed.
CORRUPTION WARNING in SBCL pid 206086 tid 206091:
Memory fault at 0x7f9c7c58b000 (pc=0x53617c03 [code 0x53617a30+0x1D3 ID 0x43a5], fp=0x7f696af2dc40, sp=0x7f696af2dc18) tid 206091
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

环境信息

  • 操作系统:LinuxMint 21
  • SBCL版本:2.2.8(更新后测试2.2.9版本仍可复现)
  • Hunchentoot版本:1.3.0

解决过程

  1. 初步解决:改用从REPL中生成可执行文件,服务器正常运行。推测问题出在脚本的--script选项上,该选项会禁用ldb调试器,不适合用来生成可执行文件。
  2. 最终方案:无需放弃脚本方式,只要避免使用--script选项即可。将以下代码放在脚本文件开头(移除原脚本最后两行),即可通过脚本生成正常工作的可执行文件:
#|
# 从该脚本生成可执行文件的正确方式
sbcl --noinform --no-userinit --load "$0" --eval $'(sb-ext:save-lisp-and-die "http-server" :toplevel \'http-server::main :executable t)'
exit 0
|#

内容的提问来源于stack exchange,提问作者xiepan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 16:41:31