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

Restart of the SMTPServer by calling stop-start #75

Open
GoogleCodeExporter opened this issue Mar 30, 2015 · 3 comments
Open

Restart of the SMTPServer by calling stop-start #75

GoogleCodeExporter opened this issue Mar 30, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link
Contributor

What steps will reproduce the problem?
1. Creat Wiser instance and start the server by calling wiser.start().
2. Call wiser.stop() to stop the SMTPServer.
3. Call wiser.start() on the same instance to start the SMTPServer again.

What is the expected output? What do you see instead?
The SMTPServer should be started again, but the second call of the 
wiser.start() throws the "java.lang.IllegalStateException: SMTPServer can only 
be started once", because is started flag is not set to false in the 
stop-method.

What version of the product are you using? On what operating system?
3.1.7

Original issue reported on code.google.com by [email protected] on 3 Feb 2015 at 12:28

@amarhin
Copy link

amarhin commented Jul 16, 2015

When you start the server with wiser.start(), an inner flag 'started' is set to true in the SMTPServer class; this one is not set to false when you stop the server with wiser.stop().

// True if this SMTPServer was started. It remains true even if the SMTPServer has been stopped since
@GuardedBy("this")
private boolean started = false;

It seems to be a deliberate comportment.

You have to instanciate a new server each time you want to create a new one.

wiser.start() // create a new server
wiser.stop() // stop the server and release resources (close sockets...)
wiser = new Wiser(port); // create a new one

Hope these few explanations will help you.

@arichiardi
Copy link

Hello! I read on this line: https://github.com/voodoodyne/subethasmtp/blob/master/src/main/java/org/subethamail/smtp/server/SMTPServer.java#L72

that the thread pool cannot be restarted...isn't ExecutorServices.shutdownNow an option?

Would you accept a PR to make the server fully stoppable/reloadable?

@arichiardi
Copy link

arichiardi commented Sep 27, 2016

This is what I do in Clojure, using reflection, it is super hacky but it works so I wonder whether a PR would be effective here.

  ;; AR - workaround - don't do this at home
  (let [{:keys [server]} state
        field (doto (.. server getClass (getDeclaredField "executorService")) (.setAccessible true))
        executor-svc (. field (get server))]
    (.stop server)
    (.shutdownNow executor-svc))

martijnhoekstra pushed a commit to martijnhoekstra/subethasmtp that referenced this issue Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants