Skip to content

Commit bc89520

Browse files
committed
Revert "handle disconnect/hibernation reconnection"
This reverts commit 15300c6.
1 parent 15300c6 commit bc89520

File tree

16 files changed

+41
-458
lines changed

16 files changed

+41
-458
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FROM node:lts-slim AS backend-deploy
2020
WORKDIR /app
2121
ENV NODE_ENV=production
2222
EXPOSE 2022
23-
RUN apt-get update && apt-get install -y lm-sensors ca-certificates
23+
RUN apt-get update && apt-get install -y iputils-ping lm-sensors
2424
COPY --from=backend-build /usr/src/app/dist/config ../config
2525
COPY --from=backend-build /usr/src/app/dist/index.js ./
2626
COPY --from=backend-build /usr/src/app/dist/package.json ./

backend/src/routes/deluge.route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ delugeRoute.post('/login', async (req: Request, res: Response) => {
222222
delugeRoute.get('/stats', async (req: Request, res: Response) => {
223223
try {
224224
const baseUrl = getBaseUrl(req);
225+
console.log(`Deluge stats request for ${baseUrl}`);
225226

226227
// Use IP address as identifier for non-authenticated users
227228
const sessionId = req.user?.username || req.ip || 'default';

frontend/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useEffect } from 'react';
55
import { Route, BrowserRouter as Router, Routes } from 'react-router-dom';
66

77
import { DashApi } from './api/dash-api';
8-
import { ConnectionStatus } from './components/ConnectionStatus';
98
import { SetupForm } from './components/forms/SetupForm';
109
import { WithNav } from './components/navbar/WithNav';
1110
import { ScrollToTop } from './components/ScrollToTop';
@@ -103,7 +102,6 @@ export const App = () => {
103102
<Route path='/signup' element={<LoginPage />}/>
104103
</Route>
105104
</Routes>
106-
<ConnectionStatus />
107105
</Router>
108106
</>
109107
);

frontend/src/api/dash-api.ts

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -90,56 +90,11 @@ export class DashApi {
9090
// Set withCredentials globally for all API requests
9191
axios.defaults.withCredentials = true;
9292

93-
// Variable to track last connection attempt time
94-
let lastConnectionAttempt = Date.now();
95-
96-
// Track if we're processing a connection retry
97-
let isRetrying = false;
98-
99-
// Listen for online/offline events
100-
window.addEventListener('online', () => {
101-
console.log('Browser reports online status');
102-
// Force a connection check when we're back online
103-
this.checkCookies().catch(e => console.error('Cookie check after online event failed', e));
104-
});
105-
10693
// Request interceptor
10794
axios.interceptors.request.use(
10895
async (config) => {
10996
// Ensure credentials are sent for all API requests
11097
config.withCredentials = true;
111-
112-
// Check if we need to update the last connection time
113-
// This is used to detect when the device has been sleeping
114-
const now = Date.now();
115-
const timeSinceLastConnection = now - lastConnectionAttempt;
116-
lastConnectionAttempt = now;
117-
118-
// If there's been an unusually long gap between requests (device sleep)
119-
// and this isn't a login/refresh/health check request, do a connection check
120-
const isAuthRequest = config.url?.includes('api/auth') || config.url?.includes('api/config') ||
121-
config.url?.includes('api/health');
122-
123-
if (timeSinceLastConnection > 60000 && !isRetrying && !isAuthRequest) {
124-
console.log(`Long time since last request (${timeSinceLastConnection}ms), checking connection`);
125-
isRetrying = true;
126-
127-
// Check connection before proceeding
128-
try {
129-
await this.checkCookies();
130-
isRetrying = false;
131-
} catch (e) {
132-
console.error('Connection check failed, attempting token refresh');
133-
try {
134-
await this.refreshToken();
135-
} catch (refreshError) {
136-
console.error('Token refresh failed after connection check', refreshError);
137-
} finally {
138-
isRetrying = false;
139-
}
140-
}
141-
}
142-
14398
return config;
14499
},
145100
(error) => Promise.reject(error)
@@ -149,47 +104,6 @@ export class DashApi {
149104
axios.interceptors.response.use(
150105
response => response,
151106
async (error) => {
152-
// Set a default retry delay to add some buffer before retrying
153-
const retryDelay = 1000;
154-
155-
// Handle device wake network issues
156-
// Common errors after device wake: ERR_NETWORK, ETIMEDOUT, ECONNABORTED
157-
if (
158-
error.code === 'ERR_NETWORK' ||
159-
error.code === 'ECONNABORTED' ||
160-
error.code === 'ETIMEDOUT' ||
161-
error.message?.includes('Network Error')
162-
) {
163-
const originalRequest = error.config;
164-
165-
// Avoid infinite retry loops
166-
if (!originalRequest._retry && !isRetrying) {
167-
originalRequest._retry = true;
168-
isRetrying = true;
169-
170-
console.log('Network error detected, attempting reconnection...');
171-
172-
// Add a delay to give network time to stabilize
173-
await new Promise(resolve => setTimeout(resolve, retryDelay));
174-
175-
try {
176-
// Try to refresh connection
177-
const refreshResult = await this.refreshToken();
178-
isRetrying = false;
179-
180-
if (refreshResult.success) {
181-
console.log('Connection restored after network error');
182-
// If refresh was successful, retry the original request
183-
return axios(originalRequest);
184-
}
185-
} catch (refreshError) {
186-
console.error('Failed to restore connection', refreshError);
187-
} finally {
188-
isRetrying = false;
189-
}
190-
}
191-
}
192-
193107
const originalRequest = error.config;
194108

195109
// Only handle 401 errors for authenticated routes

frontend/src/components/ConnectionStatus.tsx

Lines changed: 0 additions & 100 deletions
This file was deleted.

frontend/src/components/dashboard/base-items/widgets/DateTimeWidget.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
import { Box, CardContent, Typography } from '@mui/material';
22
import { useEffect, useState } from 'react';
33

4-
import { useAppContext } from '../../../../context/useAppContext';
5-
64
export const DateTimeWidget = () => {
7-
const [dateTime, setDateTime] = useState<Date>(new Date());
8-
const { refreshCounter } = useAppContext();
9-
10-
useEffect(() => {
11-
// Set initial time
12-
setDateTime(new Date());
5+
const [dateTime, setDateTime] = useState<any>(new Date());
136

14-
// Create interval to update time every minute
15-
const intervalId = setInterval(() => {
7+
useEffect(()=>{
8+
setInterval(()=>{
169
setDateTime(new Date());
1710
}, 60000);
18-
19-
// Clean up interval on component unmount
20-
return () => {
21-
clearInterval(intervalId);
22-
};
23-
}, []);
24-
25-
// Force an immediate refresh when dashboard is refreshed
26-
useEffect(() => {
27-
// Update time immediately when dashboard refreshes
28-
setDateTime(new Date());
29-
}, [refreshCounter]);
11+
},[]);
3012

3113
return (
3214
<CardContent>

frontend/src/components/dashboard/base-items/widgets/DelugeWidget.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useState } from 'react';
22

33
import { TorrentClientWidget } from './TorrentClientWidget';
44
import { DashApi } from '../../../../api/dash-api';
5-
import { useAppContext } from '../../../../context/useAppContext';
65

76
type DelugeWidgetConfig = {
87
host?: string;
@@ -16,7 +15,6 @@ type DelugeWidgetConfig = {
1615

1716
export const DelugeWidget = (props: { config?: DelugeWidgetConfig }) => {
1817
const { config } = props;
19-
const { refreshCounter } = useAppContext();
2018
const [isLoading, setIsLoading] = useState(false);
2119
const [isAuthenticated, setIsAuthenticated] = useState(false);
2220
const [authError, setAuthError] = useState('');
@@ -170,21 +168,12 @@ export const DelugeWidget = (props: { config?: DelugeWidgetConfig }) => {
170168
const interval = setInterval(() => {
171169
fetchStats();
172170
fetchTorrents();
173-
}, 30000);
171+
}, 5000); // Fixed interval of 5000ms as specified
174172

175173
return () => clearInterval(interval);
176174
}
177175
}, [fetchStats, fetchTorrents, isAuthenticated]);
178176

179-
// Force refresh when dashboard is refreshed
180-
useEffect(() => {
181-
if (isAuthenticated && !loginAttemptFailed) {
182-
console.log('Dashboard refreshed, re-fetching Deluge data');
183-
fetchStats();
184-
fetchTorrents();
185-
}
186-
}, [refreshCounter, fetchStats, fetchTorrents, isAuthenticated, loginAttemptFailed]);
187-
188177
// Torrent actions
189178
const handleResumeTorrent = useCallback(async (hash: string) => {
190179
try {

frontend/src/components/dashboard/base-items/widgets/PiholeWidget/PiholeWidget.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const initialStats: PiholeStats = {
4242

4343
export const PiholeWidget = (props: { config?: PiholeWidgetConfig }) => {
4444
const { config } = props;
45-
const { editMode, refreshCounter } = useAppContext();
45+
const { editMode } = useAppContext();
4646

4747
// Reference to track if this is the first render
4848
const isFirstRender = useRef(true);
@@ -123,14 +123,6 @@ export const PiholeWidget = (props: { config?: PiholeWidgetConfig }) => {
123123
// eslint-disable-next-line react-hooks/exhaustive-deps
124124
}, []);
125125

126-
// Force refresh when dashboard is refreshed
127-
useEffect(() => {
128-
if (!isFirstRender.current && isConfigured && !error && !authFailed) {
129-
console.log('Dashboard refreshed, re-fetching Pi-hole data');
130-
checkPiholeStatus();
131-
}
132-
}, [refreshCounter]);
133-
134126
// Determine if we're using Pi-hole v6 based on authentication method
135127
useEffect(() => {
136128
// Using password-only auth indicates Pi-hole v6

frontend/src/components/dashboard/base-items/widgets/QBittorrentWidget.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useState } from 'react';
22

33
import { TorrentClientWidget } from './TorrentClientWidget';
44
import { DashApi } from '../../../../api/dash-api';
5-
import { useAppContext } from '../../../../context/useAppContext';
65

76
type QBittorrentWidgetConfig = {
87
host?: string;
@@ -17,7 +16,6 @@ type QBittorrentWidgetConfig = {
1716

1817
export const QBittorrentWidget = (props: { config?: QBittorrentWidgetConfig }) => {
1918
const { config } = props;
20-
const { refreshCounter } = useAppContext();
2119
const [isLoading, setIsLoading] = useState(false);
2220
const [isAuthenticated, setIsAuthenticated] = useState(false);
2321
const [authError, setAuthError] = useState('');
@@ -171,21 +169,12 @@ export const QBittorrentWidget = (props: { config?: QBittorrentWidgetConfig }) =
171169
const interval = setInterval(() => {
172170
fetchStats();
173171
fetchTorrents();
174-
}, 30000);
172+
}, 5000); // Fixed interval of 5000ms as specified
175173

176174
return () => clearInterval(interval);
177175
}
178176
}, [fetchStats, fetchTorrents, isAuthenticated]);
179177

180-
// Force refresh when dashboard is refreshed
181-
useEffect(() => {
182-
if (isAuthenticated) {
183-
console.log('Dashboard refreshed, re-fetching qBittorrent data');
184-
fetchStats();
185-
fetchTorrents();
186-
}
187-
}, [refreshCounter, fetchStats, fetchTorrents, isAuthenticated]);
188-
189178
// Torrent actions
190179
const handleStartTorrent = useCallback(async (hash: string) => {
191180
try {

0 commit comments

Comments
 (0)