                                  (run-at-time "30 sec" nil
                                               (lambda (buf)
                                                 (with-current-buffer buf
-                                                  (when (consp tern-known-port) (setf tern-known-port nil))))
+                                                  (when (consp (tern-known-port)) (setf tern-known-port nil))))
                                               (current-buffer))
-                                 (funcall c nil tern-known-port)))
+                                 (funcall c nil (tern-known-port))))
     (set-process-filter proc (lambda (proc output)
                                (if (not (string-match "Listening on port \\([0-9][0-9]*\\)" output))
                                    (setf all-output (concat all-output output))

                                                              (delete-process proc)
                                                              (setf tern-known-port nil)))
                                 (set-process-filter proc nil)
                                 (funcall c tern-known-port nil))))))

(defvar tern-command-generation 0)
(defvar tern-activity-since-command -1)

                                 (or (eq (cl-cadar err) 'connection-failed)
                                     (eq (caar err) 'file-error)))
                            (setf retrying t)
                            (let ((old-port (tern-known-port)))
                              (setf tern-known-port nil)
                              (if tern-explicit-port
                                  (funcall callback nil err)
