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


                @emit 'connect'    # successful connection

                cb?()

    ui_loading: () =>
        @element.find(".salvus-editor-codemirror-loading").show()

                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
