NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.05k stars 14.04k forks source link

Woo crashes when compiled #252016

Closed autrimpo closed 1 year ago

autrimpo commented 1 year ago

Describe the bug

Lisp packages using Woo seem unable to be compiled into a binary.

I began working on a small project today which uses Clack with Woo. When running the program in Sly REPL, everything worked fine. Once I attempted to make a Nix package to deploy, every HTTP request would segfault the program. I managed to track down the issue to woo.response::current-rfc-1123-timestamp - my Lisp skills are not good enough to determine whether this is a Nix issue, SBCL issue or Woo issue, but since it works in the REPL, I'm assuming the first case.

The binary packaging was taken from the Lem flake.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Clone https://github.com/autrimpo/woo-repro
  2. Run nix run
    
    debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
    #<THREAD tid=140152 "main thread" RUNNING {1001B58003}>:
    Attempt to modify a read-only object at #xFFFB7E578.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name): 0: [ABORT] Exit from the current thread.

(WOO.RESPONSE::CURRENT-RFC-1123-TIMESTAMP) source: (DEFUN CURRENT-RFC-1123-TIMESTAMP () (DECLARE (OPTIMIZE (SPEED 3) (SAFETY 0))) (MACROLET ((WRITE-DATE (VAL START &OPTIONAL (LEN ')) `(REPLACE DATE-HEADER* (THE # ,VAL) :START1 ,START)) (WRITE-CHAR-TO-DATE (CHAR IDX) (SETF # ,CHAR)) (WRITE-INT-TO-DATE (VAL START) (CHECK-TYPE START INTEGER) (IF (< ,VAL 10) (PROGN # #) (MULTIPLE-VALUE-BIND # # # #)))) (MULTIPLE-VALUE-BIND (SEC MINUTE HOUR DAY MONTH YEAR WEEKDAY) (DECODE-UNIVERSAL-TIME (GET-UNIVERSAL-TIME) 0) (DECLARE (TYPE FIXNUM SEC MINUTE HOUR DAY MONTH YEAR WEEKDAY)) (WRITE-DATE (SVREF #("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun") WEEKDAY) 0 3) (WRITE-INT-TO-DATE DAY 5) (WRITE-DATE (SVREF

("" "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep"

                 "Oct" "Nov" ...)
               MONTH)
              8 3)
             (MULTIPLE-VALUE-BIND (QUOTIENT REMAINDER)
                 (FLOOR (THE # YEAR) 1000)
               (WRITE-CHAR-TO-DATE (INTEGER-TO-CHARACTER QUOTIENT) 12)
               (MULTIPLE-VALUE-BIND (QUOTIENT REMAINDER)
                   (FLOOR REMAINDER 100)
                 (WRITE-CHAR-TO-DATE # 13)
                 (MULTIPLE-VALUE-BIND # # # #)))
             (WRITE-INT-TO-DATE HOUR 17)
             (WRITE-INT-TO-DATE MINUTE 20)
             (WRITE-INT-TO-DATE SEC 23)))
         *DATE-HEADER*)

0]

3. Run `(woo-repro:main)` in Sly REPL

CL-USER> (woo-repro:main) "Mon, 28 Aug 2023 17:43:12 GMT" CL-USER>



### Notify maintainers

@Uthar - Thank you for the new Lisp infrastructure, it's much more pleasant to work with!

<!--
Please @ people who are in the `meta.maintainers` list of the offending package or module.
If in doubt, check `git blame` for whoever last touched something.
-->

### Metadata
See minimal repro [flake](https://github.com/autrimpo/woo-repro).
Uthar commented 1 year ago

Hi autrimpo - this is a bug in Woo caused by using mutation functions on a string literal. I was able to fix it with a patch: you can test by running nix run github:uthar/woo-repro?rev=1be6991d8198efa5cf1384f2fbf6649a4dc04ec4.

It also happens using regular sbcl with quicklisp. So I submitted a patch to upstream: https://github.com/fukamachi/woo/pull/106

Thank you for the new Lisp infrastructure, it's much more pleasant to work with!

I'm glad you're enjoying it :-)

autrimpo commented 1 year ago

Awesome, thank you for the patch :)