mat813 / rb-kqueue

An FFI wrapper for kqueue
MIT License
22 stars 12 forks source link

Exception in finalizer #17

Closed JoeSSS closed 2 years ago

JoeSSS commented 2 years ago

After #15 we started to get:

Exception in finalizer #<Proc:0x0000000108289a20 ...ruby-3.1.0/gems/rb-kqueue-0.2.7/lib/rb-kqueue/watcher/file.rb:45 (lambda)>
...rb-kqueue-0.2.7/lib/rb-kqueue/watcher/file.rb:45:in `block in finalizer': wrong number of arguments (given 1, expected 0) (ArgumentError)

We run kqueue like this:

@thread = Thread.new do
  Thread.current.abort_on_exception = true
  queue = KQueue::Queue.new
  queue.watch_file(logfile, :extend) do
      operation_on(file.read)
   end
   queue.run
end

when we kill the thread Thread.kill(@thread) the exception is raised and since we use abort_on_exception = true, this results in crashes in unrelated part of code of other gems.

Most likely we do something weird here, would be happy to hear any suggestions.

JoeSSS commented 2 years ago

@marvinthepa can you maybe take a look, since you definitely understand the finalizer better than I do :)

dsh2dsh commented 2 years ago

I've just got the same issue during upgrade from ruby 3.0 to 3.1

dsh2dsh commented 2 years ago

If it helps, I found it in ri ObjectSpace.define_finalizer

If aProc is a lambda or method, make sure it can be called with a single argument.

marvinthepa commented 2 years ago

@marvinthepa can you maybe take a look, since you definitely understand the finalizer better than I do :)

Sorry, I was indisposed. Also sorry for this mistake in the finalizer.

18 looks good to me, although I also would make the argument optional (as it says "make sure it can be called with a single argument").

dsh2dsh commented 2 years ago

@marvinthepa thanks, I've made it optional.

gregschmit commented 2 years ago

Merged and released as 0.2.8.