Skip to content

destroy VS contextDestroyed  #218

Open
@dpiliouras

Description

Before i say anything, please bear in mind that I am not a Servlet container expert. I'm purely going off of an entire day's worth of research, while trying to understand why our destroy fns are not being called.

Per the .destroy docs:

This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.

Contrast that with the .contextDestroyed docs:

All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction.

Basically, if I'm understanding correctly by the time .contextDestroyed has been called, it's too late to do anything meaningful - even something as trivial as logging. Here is a related SO discussion.

A typical destroy fn for us looks something like this:

(defn tomcat-destroy []
  (when (realized? SYSTEM) ;; promise delivered on system init
    (ig/halt! @SYSTEM) ;; certain components write to disk on `ig/halt-key!`
    (l/trace "Halted system")
    (shutdown-agents)))

As you can see, our use-case aligns perfectly with the Servlet::destroy docs.
So again, with my somewhat limited understanding, i suspect that instead of implementing contextDestroyed on the listener class, we should probably override the destroy method on the servlet itself.

I'd love to know what you think. Have a great weekend 👍

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions