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

Closing the listener produces at least one error message to handler, sometimes several. #311

Open
RokLenarcic opened this issue Jun 2, 2024 · 4 comments

Comments

@RokLenarcic
Copy link

I'm running this code here:

(ns memento.redis.listener3-test
  (:require [clojure.test :refer :all]
            [taoensso.carmine :as car]))

(deftest listener-subscription-test
  (testing "messages work"
    (let [p (promise)]
      (with-open [l (car/with-new-listener {}
                      (fn [[typ :as x] state]
                        (println x)
                        (when (= "message" typ)
                          (deliver p x))) {}
                      (car/subscribe "test-chan"))]
        (car/wcar {}
          (car/publish "test-chan" [1]))
        (is (= ["message" "test-chan" [1]] @p))))))

So this posts a message and closes listener and it awaits for the message to get back from redis.

First thing is that this always produces an error message to the listener:

[subscribe test-chan 1]
[message test-chan [1]]
[carmine carmine:listener:error {:error :conn-closed, :throwable ,  :listener{:type :end-test-var, :ns "memento.redis.listener3-test", :name "listener-subscription-test", :file "/Users/roklenarcic/clojure-projects/memento-redis/test/memento/redis/listener3_test.clj", :line 5, :column 1} #taoensso.carmine.Listener{:connection #taoensso.carmine.connections.Connection{:socket #object[java.net.Socket 0x7b641dbe Socket[addr=/127.0.0.1,port=6379,localport=64296]], :spec {:host 127.0.0.1, :port 6379, :listener? true}, :in #object[java.io.DataInputStream 0x3dca26c0 java.io.DataInputStream@3dca26c0], :out #object[java.io.BufferedOutputStream 0x10bf2d5d java.io.BufferedOutputStream@10bf2d5d]}, :handler #object[clojure.lang.Atom 0x53bfef3e {:status :ready, :val Ran 1 test containing 1 assertion.
... etc

But if I run this test in REPL a couple of times in a row I get runs that look like this:

[subscribe test-chan 1]
[message test-chan [1]]
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{...
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{...
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{...
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{...
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....
[carmine carmine:listener:error {:error :conn-closed, :throwable nil, :listener #taoensso.carmine.Listener{....

It instantly calls the listener handler fn with 11 instances of same error message.

@ptaoussanis
Copy link
Member

Just to make sure that we're on the same page, could you please clarify exactly what your question is or what behaviour you're expecting?

Are you surprised that any error message is triggered, or that you're seeing multiple error messages? If the latter - how many times are you running the test in your REPL?

@RokLenarcic
Copy link
Author

RokLenarcic commented Jun 3, 2024

Both. So I am surprised that I get an error message at all, since closing the listener seems like a legitimate usecase. I guess it's not that hard to filter that out in the handler.

But the other thing is just confusing. I am running a single test and I get either 1 or 12 errors. I don't understand the mechanism behind that.

@RokLenarcic
Copy link
Author

To be more specific, running the test code I pasted above in a fresh JVM usually produces 1 conn-closed error, but sometimes it produces 12 conn-closed errors. That's a single run in freshly started JVM. I am just trying to make sure I am not missing something here.

@RokLenarcic
Copy link
Author

Screen.Recording.2024-06-03.at.11.33.48.mov

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