From 9070d8e425c20c2b3b0579e6d3d57d10c168acca Mon Sep 17 00:00:00 2001 From: Mohammed Ehab Date: Mon, 9 Jun 2025 16:12:06 +0100 Subject: [PATCH 1/4] Handle Interrupts to the Runtime API Http Requests Gracefully and Version Bump to 3.1.3. --- RELEASE.CHANGELOG.md | 4 ++++ lib/aws_lambda_ric/lambda_server.rb | 3 +++ lib/aws_lambda_ric/version.rb | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/RELEASE.CHANGELOG.md b/RELEASE.CHANGELOG.md index b3927ae..2fbb46b 100644 --- a/RELEASE.CHANGELOG.md +++ b/RELEASE.CHANGELOG.md @@ -1,3 +1,7 @@ +### Jun 10, 2025 +`3.1.3` +- Handle Interrupts to the Runtime API Http Requests Gracefully and Version Bump to 3.1.3. ([#50](https://github.com/aws/aws-lambda-ruby-runtime-interface-client/pull/50)) + ### Jun 6, 2025 `3.1.2` - Don't Ignore Custom Formatters. ([#49](https://github.com/aws/aws-lambda-ruby-runtime-interface-client/pull/49)) diff --git a/lib/aws_lambda_ric/lambda_server.rb b/lib/aws_lambda_ric/lambda_server.rb index c5850ed..ae4294f 100644 --- a/lib/aws_lambda_ric/lambda_server.rb +++ b/lib/aws_lambda_ric/lambda_server.rb @@ -33,6 +33,9 @@ def next_invocation "Received #{resp.code} when waiting for next invocation." ) end + rescue Interrupt + puts "Next invocation HTTP request from the runtime interface client was interrupted, gracefully shutting down." + exit 0 rescue LambdaErrors::InvocationError => e raise e rescue StandardError => e diff --git a/lib/aws_lambda_ric/version.rb b/lib/aws_lambda_ric/version.rb index 8c8c8af..c4b5704 100644 --- a/lib/aws_lambda_ric/version.rb +++ b/lib/aws_lambda_ric/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module AwsLambdaRIC - VERSION = '3.1.2' + VERSION = '3.1.3' end From 2a6f59c5fb43f57fa5f61c2116781bf274e8bffd Mon Sep 17 00:00:00 2001 From: Mohammed Ehab Date: Mon, 9 Jun 2025 17:44:56 +0100 Subject: [PATCH 2/4] Handle all signal exceptions --- RELEASE.CHANGELOG.md | 2 +- lib/aws_lambda_ric/lambda_server.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RELEASE.CHANGELOG.md b/RELEASE.CHANGELOG.md index 2fbb46b..757a241 100644 --- a/RELEASE.CHANGELOG.md +++ b/RELEASE.CHANGELOG.md @@ -1,6 +1,6 @@ ### Jun 10, 2025 `3.1.3` -- Handle Interrupts to the Runtime API Http Requests Gracefully and Version Bump to 3.1.3. ([#50](https://github.com/aws/aws-lambda-ruby-runtime-interface-client/pull/50)) +- Handle Signal Exceptions during Runtime API Http Requests Gracefully and Version Bump to 3.1.3 ([#50](https://github.com/aws/aws-lambda-ruby-runtime-interface-client/pull/50)) ### Jun 6, 2025 `3.1.2` diff --git a/lib/aws_lambda_ric/lambda_server.rb b/lib/aws_lambda_ric/lambda_server.rb index ae4294f..d11afb1 100644 --- a/lib/aws_lambda_ric/lambda_server.rb +++ b/lib/aws_lambda_ric/lambda_server.rb @@ -33,8 +33,8 @@ def next_invocation "Received #{resp.code} when waiting for next invocation." ) end - rescue Interrupt - puts "Next invocation HTTP request from the runtime interface client was interrupted, gracefully shutting down." + rescue SignalException => sig + puts "Next invocation HTTP request from the runtime interface client was interrupted with a #{sig} SIGNAL, gracefully shutting down." exit 0 rescue LambdaErrors::InvocationError => e raise e From 889768506b3ad774b57f53613487930a92b2ebf0 Mon Sep 17 00:00:00 2001 From: Mohammed Ehab Date: Mon, 9 Jun 2025 17:58:45 +0100 Subject: [PATCH 3/4] Use invocationError --- lib/aws_lambda_ric/lambda_server.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/aws_lambda_ric/lambda_server.rb b/lib/aws_lambda_ric/lambda_server.rb index d11afb1..b4e0070 100644 --- a/lib/aws_lambda_ric/lambda_server.rb +++ b/lib/aws_lambda_ric/lambda_server.rb @@ -34,8 +34,7 @@ def next_invocation ) end rescue SignalException => sig - puts "Next invocation HTTP request from the runtime interface client was interrupted with a #{sig} SIGNAL, gracefully shutting down." - exit 0 + raise LambdaErrors::InvocationError.new("Next invocation HTTP request from the runtime interface client was interrupted with a #{sig} SIGNAL, gracefully shutting down.") rescue LambdaErrors::InvocationError => e raise e rescue StandardError => e From 8dff1323bf975360a149c8b02f604b160927ae27 Mon Sep 17 00:00:00 2001 From: Mohammed Ehab Date: Wed, 11 Jun 2025 12:11:15 +0100 Subject: [PATCH 4/4] Add Unit Test --- test/unit/lambda_server_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit/lambda_server_test.rb b/test/unit/lambda_server_test.rb index fb2e248..d08bc9f 100644 --- a/test/unit/lambda_server_test.rb +++ b/test/unit/lambda_server_test.rb @@ -15,6 +15,23 @@ def setup @under_test = RapidClient.new(@server_address, @mock_user_agent) end + def test_next_invocation_handles_different_signals + ['INT', 'TERM', 'QUIT'].each do |signal| + http_mock = Minitest::Mock.new + http_mock.expect(:read_timeout=, nil, [RapidClient::LONG_TIMEOUT_MS]) + http_mock.expect(:start, nil) { raise SignalException.new(signal) } + + Net::HTTP.stub :new, http_mock do + error = assert_raises(LambdaErrors::InvocationError) do + @under_test.next_invocation + end + + assert_match(/Next invocation HTTP request from the runtime interface client was interrupted with a SIG#{signal} SIGNAL, gracefully shutting down./, error.message) + http_mock.verify + end + end + end + def test_post_invocation_error_with_large_xray_cause large_xray_cause = ('a' * 1024 * 1024)[0..-2] headers = {'Lambda-Runtime-Function-Error-Type' => @error.runtime_error_type,