Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ modules:
readiness-health-check-http-endpoint: /health
properties:
REPOSITORY_ID: REPLACE_WITH_YOUR_REPOSITORY_ID
CDS_LOG_LEVELS_SDM: info
INCOMING_REQUEST_TIMEOUT: 3600000
INCOMING_SESSION_TIMEOUT: 3600000
INCOMING_CONNECTION_TIMEOUT: 3600000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ modules:
readiness-health-check-http-endpoint: /health
properties:
REPOSITORY_ID: REPLACE_WITH_YOUR_REPOSITORY_ID
CDS_LOG_LEVELS_SDM: info
INCOMING_REQUEST_TIMEOUT: 3600000
INCOMING_SESSION_TIMEOUT: 3600000
INCOMING_CONNECTION_TIMEOUT: 3600000
Expand Down
1 change: 1 addition & 0 deletions app/single-tenant/central-space/incidents-app/mta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ modules:
buildpack: nodejs_buildpack
properties:
REPOSITORY_ID: REPLACE_WITH_YOUR_REPOSITORY_ID
CDS_LOG_LEVELS_SDM: info
INCOMING_REQUEST_TIMEOUT: 3600000
INCOMING_SESSION_TIMEOUT: 3600000
INCOMING_CONNECTION_TIMEOUT: 3600000
Expand Down
1 change: 1 addition & 0 deletions app/single-tenant/personal-space/incidents-app/mta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ modules:
buildpack: nodejs_buildpack
properties:
REPOSITORY_ID: ${REPOSITORY_ID}
CDS_LOG_LEVELS_SDM: info
INCOMING_REQUEST_TIMEOUT: 3600000
INCOMING_SESSION_TIMEOUT: 3600000
INCOMING_CONNECTION_TIMEOUT: 3600000
Expand Down
19 changes: 11 additions & 8 deletions lib/ReadAheadStream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { EventEmitter } = require('events');
const cds = require('@sap/cds/lib');

const LOG = cds.log('sdm');

/**
* ReadAheadStream wraps a source stream and reads chunks into a bounded queue
Expand Down Expand Up @@ -30,7 +33,7 @@ class ReadAheadStream extends EventEmitter {
this.readPromise = null;
this.maxRetries = 5;

console.log('[ReadAheadStream] Initializing read-ahead stream for large file upload');
LOG.info('[INFO] [ReadAheadStream] Initializing read-ahead stream for large file upload');
}

/**
Expand Down Expand Up @@ -75,7 +78,7 @@ class ReadAheadStream extends EventEmitter {
offset = end;
}
this.lastChunkLoaded = true;
console.log('[ReadAheadStream] Last chunk successfully queued and marked (Buffer path).');
LOG.debug('[DEBUG] [ReadAheadStream] Last chunk successfully queued and marked (Buffer path).');
return;
}

Expand All @@ -102,16 +105,16 @@ class ReadAheadStream extends EventEmitter {

if (this.totalBytesRead >= this.totalSize) {
this.lastChunkLoaded = true;
console.log('[ReadAheadStream] Last chunk successfully queued and marked.');
LOG.debug('[DEBUG] [ReadAheadStream] Last chunk successfully queued and marked.');
break;
}
} else {
console.warn('[ReadAheadStream] No bytes read from stream. Possible EOF.');
LOG.warn('[WARN] [ReadAheadStream] No bytes read from stream. Possible EOF.');
break;
}
}
} catch (error) {
console.error('[ReadAheadStream] Unexpected exception during background loading', error);
LOG.error('[FATAL] [ReadAheadStream] Unexpected exception during background loading', error);
this.readError = error;
// Do NOT emit('error') — if there are no listeners Node.js throws an
// uncaught exception and crashes the process. Callers poll readError
Expand Down Expand Up @@ -153,7 +156,7 @@ class ReadAheadStream extends EventEmitter {
throw new Error(`Failed to read chunk after ${this.maxRetries} retries: ${error.message}`);
}
const delayMs = Math.pow(2, retryCount) * 1000; // 2s, 4s, 8s, 16s, 32s
console.log(`[ReadAheadStream] Retry ${retryCount} in ${delayMs / 1000}s: ${error.message}`);
LOG.warn(`[WARN] [ReadAheadStream] Retry ${retryCount} in ${delayMs / 1000}s: ${error.message}`);
await this._sleep(delayMs);
} else {
throw error;
Expand Down Expand Up @@ -257,7 +260,7 @@ class ReadAheadStream extends EventEmitter {
const last = await this._pollQueue(2000);
if (last !== null) return last;
}
console.error('[ReadAheadStream] No last chunk found in queue. Returning empty.');
LOG.error('[ERROR] [ReadAheadStream] No last chunk found in queue. Returning empty.');
return Buffer.allocUnsafe(0);
}

Expand Down Expand Up @@ -354,7 +357,7 @@ class ReadAheadStream extends EventEmitter {
new Promise(resolve => setTimeout(() => resolve(TIMEOUT), 5000).unref())
]);
if (result === TIMEOUT) {
console.error('[ReadAheadStream] Forcing stream shutdown after timeout');
LOG.warn('[WARN] [ReadAheadStream] Forcing stream shutdown after timeout');
this.lastChunkLoaded = true;
}
}
Expand Down
Loading
Loading