Search code examples
clojurejvmread-eval-print-loop

JVM: Is it possible hotfix/patch production code via remote Clojure repl?


In Clojure for Java Programmers Part 1 talk Rich Hickey mentions this as one of the benefits of Clojure:

If you build an application with some access to the ability to load code - either a remote repl connection or some way to do that. Your running production systems will have this capability to have fixes loaded into running programs.

I'm wondering how easy it is in practice. Let's say I know there is a bug in one function and I want to redefine/override it in production via remote repl

  • Is it possible?
  • Will the overridden version stay active after I exit the repl?
  • Is this behavior in all JVM application containers?

I don't have any experience of using JVM in production and that's the reason for asking this question.


Solution

  • Is it possible?

    Yes, I would recommend watching The Joys and Perils of Interactive Development - Stuart Sierra he tells a story of NASA hotfixing a satellite in space using the REPL.

    Will the overridden version stay active after I exit the repl?

    When you reevaluate the function the changes will apply everywhere so for example

    (defn add1 [x]
      (+ x 2))
    
    (defn foo [x]
      (add1 x))
    
    (foo 1)
    

    Notice (foo 1) => 3 if you fix and reevaluate add1 then run again (foo 1) => 2