mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-02 03:52:13 +03:00
Merge pull request #5686 from urbit/lf/fix-reconnects-three-point-oh-you-cannot-redo
interface: fix reconnect bugs
This commit is contained in:
commit
51c65247fc
@ -12,9 +12,17 @@ import useStorageState from '../state/storage';
|
||||
import gcpManager from '../lib/gcpManager';
|
||||
|
||||
export async function bootstrapApi() {
|
||||
airlock.reset();
|
||||
airlock.onError = (e) => {
|
||||
(async () => {
|
||||
const { reconnect } = useLocalState.getState();
|
||||
const { reconnect, errorCount, set } = useLocalState.getState();
|
||||
console.log(errorCount);
|
||||
if(errorCount > 1) {
|
||||
set(s => {
|
||||
s.subscription = 'disconnected';
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await reconnect();
|
||||
} catch (e) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Urbit from '@urbit/http-api';
|
||||
const api = new Urbit('', '', (window as any).desk);
|
||||
api.ship = window.ship;
|
||||
// api.verbose = true;
|
||||
api.verbose = true;
|
||||
// @ts-ignore TODO window typings
|
||||
window.api = api;
|
||||
|
||||
|
@ -82,19 +82,17 @@ const useLocalState = create<LocalStateZus>(persist((set, get) => ({
|
||||
// resume doesn't work properly
|
||||
reconnect: async () => {
|
||||
const { errorCount } = get();
|
||||
set(s => ({ errorCount: s.errorCount+1, subscription: 'reconnecting' }));
|
||||
|
||||
if(errorCount > 5) {
|
||||
set({ subscription: 'disconnected' });
|
||||
if(errorCount > 1) {
|
||||
return;
|
||||
}
|
||||
await wait(Math.pow(2, errorCount) * 750);
|
||||
set(s => ({ subscription: 'reconnecting', errorCount: s.errorCount + 1 }));
|
||||
console.log(get().errorCount);
|
||||
|
||||
try {
|
||||
airlock.reset();
|
||||
await bootstrapApi();
|
||||
} catch (e) {
|
||||
console.error(`Retrying connection, attempt #${errorCount}`);
|
||||
console.error(e);
|
||||
set({ subscription: 'disconnected' });
|
||||
}
|
||||
},
|
||||
bootstrap: async () => {
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
SSEOptions,
|
||||
PokeHandlers,
|
||||
Message,
|
||||
FatalError,
|
||||
} from './types';
|
||||
import { hexString } from './utils';
|
||||
|
||||
@ -291,7 +292,7 @@ export class Urbit {
|
||||
},
|
||||
onerror: (error) => {
|
||||
console.warn(error);
|
||||
if (this.errorCount++ < 4) {
|
||||
if (!(error instanceof FatalError) && this.errorCount++ < 4) {
|
||||
this.onRetry && this.onRetry();
|
||||
return Math.pow(2, this.errorCount - 1) * 750;
|
||||
}
|
||||
@ -311,6 +312,9 @@ export class Urbit {
|
||||
*
|
||||
*/
|
||||
reset() {
|
||||
if(this.verbose) {
|
||||
console.log('resetting');
|
||||
}
|
||||
this.delete();
|
||||
this.abort.abort();
|
||||
this.abort = new AbortController();
|
||||
|
Loading…
Reference in New Issue
Block a user