code: private void closeSoon() {
          isClosing.set(true);
          @NotNull ScheduledExecutorService closer = newSingleThreadScheduledExecutor(new NamedThreadFactory("closer", true));
          closer.schedule(() -> {
              closer.shutdown();
              close();
          }, 2, SECONDS);
      }
docs: wait 2 seconds before closing the socket connection, this should allow time of the
  termination event to be sent.