     # "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()

                if resp.event == 'error'
                    err = resp.error
                if err
                    delete @_connect_lock
                    cb?(err); return

                @session_uuid = resp.session_uuid
                @readonly = resp.readonly

                patch = undefined
                synced_before = false
                if @_last_sync?
                    # We have sync'd before.
                    @_presync?() # give syncstring chance to be updated by true live.
                    patch = @dsync_client._compute_edits(@_last_sync, @live())
                    synced_before = true

                @dsync_client = new diffsync.DiffSync(doc:resp.content)

                if not synced_before
                    # This initialiation is the first.
                    @_last_sync   = resp.content
                    reconnect = false
