     # "connect(cb)": Connect to the given server; will retry until it succeeds.
     # _connect(cb): Try once to connect and on any error, cb(err).
     _connect: (cb) =>
+
+        if @_connect_lock  # this lock is purely defense programming; it should be impossible for it to be hit.
+            m = "bug -- connect_lock bug in SynchronizedString; this should never happen -- PLEASE REPORT!"
+            alert_message(type:"error", message:m)
+            cb(m)
+        @_connect_lock = true
+
         @_remove_listeners()
         delete @session_uuid
         #console.log("_connect -- '#{@filename}'")

                if reconnect
                    @emit('reconnect')

                cb?()

    disconnect_from_session: (cb) =>
        @_remove_listeners()

        super(cb)

    _connect: (cb) =>
        if @_connect_lock  # this lock is purely defense programming; it should be impossible for it to be hit.
            m = "bug -- connect_lock bug in SynchronizedDocument; this should never happen -- PLEASE REPORT!"
            alert_message(type:"error", message:m)
            cb(m)

        @_remove_listeners()
        @other_cursors = {}
        delete @session_uuid
