Improve Socket.IO logging and connection handling
- Enhanced logging during WebSocket upgrade attempts by including specific headers for better debugging. - Updated frontend socket service to allow forced upgrade attempts after successful polling connections, improving connection reliability.
This commit is contained in:
@@ -50,14 +50,17 @@ export const initializeSocketIO = (httpServer) => {
|
||||
// Verbesserte WebSocket-Upgrade-Logging
|
||||
io.engine.on('upgrade', (req, socket, head) => {
|
||||
console.log(`🔄 Socket.IO Upgrade-Versuch: ${req.url}`);
|
||||
console.log(` Headers:`, req.headers);
|
||||
console.log(` Upgrade-Header: ${req.headers.upgrade}`);
|
||||
console.log(` Connection-Header: ${req.headers.connection}`);
|
||||
console.log(` Sec-WebSocket-Key: ${req.headers['sec-websocket-key']?.substring(0, 20)}...`);
|
||||
});
|
||||
|
||||
io.engine.on('upgradeError', (err, req, socket, head) => {
|
||||
console.error('❌ Socket.IO Upgrade Error:', err.message || err);
|
||||
if (req) {
|
||||
console.error(' URL:', req.url);
|
||||
console.error(' Headers:', req.headers);
|
||||
console.error(' Upgrade-Header:', req.headers.upgrade);
|
||||
console.error(' Connection-Header:', req.headers.connection);
|
||||
console.error(' Method:', req.method);
|
||||
}
|
||||
if (err.stack) {
|
||||
|
||||
@@ -85,14 +85,16 @@ export const connectSocket = (clubId) => {
|
||||
reconnectionDelayMax: 5000,
|
||||
reconnectionAttempts: Infinity, // Unbegrenzte Versuche
|
||||
timeout: 20000,
|
||||
upgrade: true,
|
||||
upgrade: true, // Erlaube Upgrade von Polling zu WebSocket
|
||||
forceNew: false,
|
||||
secure: isHttps, // Nur für HTTPS
|
||||
rejectUnauthorized: false, // Für selbst-signierte Zertifikate (nur Entwicklung)
|
||||
// Verbesserte Cookie-Handling
|
||||
withCredentials: true,
|
||||
// Auto-Connect
|
||||
autoConnect: true
|
||||
autoConnect: true,
|
||||
// Erzwinge Upgrade-Versuch nach erfolgreicher Polling-Verbindung
|
||||
rememberUpgrade: true
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
|
||||
Reference in New Issue
Block a user