-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Koa Server Request Timeout (#2504) * Add Koa Server Request Timeout * fix: Added test and documentation to the server request timeout setting. fix: Added doc updated. fix: Bumped timeout to 60 seconds. fix: removed only. fix: Added empty line. Update packages/server/src/index.ts fix: Applied feedback fix: Added back the chai. fix: Restored the chai exclude fix: Removed the async in the sendJsonRpcRequestWithDelay fix: Reduced the timeout to allow tests to finish. fix: Moved timeout test to rateLimiter. fix: Removed comma after LIMIT_DURATION fix: Bumped up the timeout delay to ensure it works in CI. fix: Testing in CI. Removed the .only fix: Adjusted the test delay. fix: Added error details. fix: Added more debug info. fix: Added delay for linux. Debugging in CI. fix: Debugging in CI. Setting test timeout fix: Debugging in CI. Nested promise. fix: Including delay in testfile. Debugging CI. fix: Debugging in CIfix: Debugging in CI. Updated package-log. fix: Extracted setting logic to util function to be used in server startup and test framework fix: Bumped up the timeout for tests on local node. * fix: Moved into its own CI job. * fix: Cleanup * fix: Clean up. --------- Signed-off-by: Nana Essilfie-Conduah <nana@swirldslabs.com> Signed-off-by: ebadiere <ebadiere@gmail.com> Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com> Co-authored-by: Nana Essilfie-Conduah <56320167+Nana-EC@users.noreply.github.com> Co-authored-by: ebadiere <ebadiere@gmail.com>
- Loading branch information
1 parent
d0a8ceb
commit 859fc4a
Showing
13 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import type { Server } from 'http'; | ||
|
||
export function setServerTimeout(server: Server): void { | ||
const requestTimeoutMs = parseInt(process.env.SERVER_REQUEST_TIMEOUT_MS ?? '60000'); | ||
server.setTimeout(requestTimeoutMs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { expect } from 'chai'; | ||
import { Utils } from '../helpers/utils'; | ||
|
||
describe('@server-config Server Configuration Options Coverage', function () { | ||
describe('Koa Server Timeout', () => { | ||
it('should timeout a request after the specified time', async () => { | ||
const requestTimeoutMs: number = parseInt(process.env.SERVER_REQUEST_TIMEOUT_MS || '3000'); | ||
const host = 'localhost'; | ||
const port = parseInt(process.env.SERVER_PORT || '7546'); | ||
const method = 'eth_blockNumber'; | ||
const params: any[] = []; | ||
|
||
try { | ||
await Utils.sendJsonRpcRequestWithDelay(host, port, method, params, requestTimeoutMs + 1000); | ||
throw new Error('Request did not timeout as expected'); // Force the test to fail if the request does not time out | ||
} catch (err) { | ||
expect(err.code).to.equal('ECONNRESET'); | ||
expect(err.message).to.equal('socket hang up'); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters