     # "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 resp.event == 'error'
                    err = resp.error
                if err
                    cb?(err); return

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

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

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

                if @_last_sync?
                    # applying missed patches to the new upstream version that we just got from the hub.
                    @_apply_patch_to_live(patch)
                    reconnect = true
                else
                    # This initialiation is the first.
                    @_last_sync   = resp.content
                    reconnect = false

        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
