Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong error handling flow on Lispworks #2

Open
svetlyak40wt opened this issue Dec 26, 2020 · 3 comments
Open

Wrong error handling flow on Lispworks #2

svetlyak40wt opened this issue Dec 26, 2020 · 3 comments

Comments

@svetlyak40wt
Copy link
Collaborator

svetlyak40wt commented Dec 26, 2020

Using with-timeout on Lispworks I encounter strange behaviour when calling a code which signals an error.

From this simple code I expect it return NIL, but it shows debugger window instead:

CL-USER > (defun test-timeout ()
            (ignore-errors
              (trivial-timeout:with-timeout (3)
                (error "Foo"))))

# It will show a dialog window about the error in the WITH-TIMEOUT process,
# and while you are deciding to open GUI debugger, window will be closed
# and result returned:
CL-USER > (ignore-errors (test-timeout))
NIL
#<COM.METABANG.TRIVIAL-TIMEOUT:TIMEOUT-ERROR 4020060D5B>

This happens because error is signalled in a separate thread, not in the thread where I use ignore-errors.

The same code on SBCL behaves as expected.

I've tested different ways how to overcome this issue and created this code:

(defun run-with-interrupt (timeout func &rest args)
  (let ((main (mp:get-current-process))
        (done nil))
    (mp:process-run-function "killer" ()
                             (lambda ()
                               (mp:process-wait-with-timeout "waiting for murder" timeout)
                               (mp:process-interrupt main
                                                     (lambda ()
                                                       (unless done
                                                         (cerror "Timeout" 'trivial-timeout:timeout-error))))))
    (handler-bind ((error (lambda (c)
                            (declare (ignore c))
                            (setf done t))))
      
      (multiple-value-prog1
          (apply func args)
        (setf done t)))))

It also starts a separate thread but it only tracks timeout and interrupts the main thread in case of errors. This way, error handling works like expected.

@gwkkwg if you OK with such code, I'll reformat it into the generate-platform-specific-code function and will create a pull-request.

Also, it would be nice if you tell me how to how to generate a report for unit-tests, because right now one of two tests fails on SBCL and Lispworks, but I can't figure out why:

CL-USER 82 > (lift:run-tests)
Start: TRIVIAL-TIMEOUT-TEST
#<Results for TRIVIAL-TIMEOUT-TEST 1 Test, 1 Error>
@gwkkwg
Copy link
Collaborator

gwkkwg commented Dec 28, 2020 via email

@svetlyak40wt
Copy link
Collaborator Author

If you would like to have commit rights, that would be even better :-)

Yes, this would be nice. I can maintain this library.

@svetlyak40wt
Copy link
Collaborator Author

Hi, @gwkkwg!

Finally I found the time to fix this bug and created these two pulls:

Please, review them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants