Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParseException when publishing batch to SNS #1293

Closed
schurmann opened this issue Apr 25, 2024 · 5 comments · Fixed by smithy-lang/smithy-kotlin#1082
Closed

ParseException when publishing batch to SNS #1293

schurmann opened this issue Apr 25, 2024 · 5 comments · Fixed by smithy-lang/smithy-kotlin#1082
Assignees
Labels
bug This issue is a bug.

Comments

@schurmann
Copy link

schurmann commented Apr 25, 2024

Describe the bug

When publishing a batch to SNS, I sometimes see ParseException. This happens when ClockSkewInterceptor is parsing the Date response header to detect clock skew and Date header is using an obsolete format with 2 digits year. When the format is 4 digit year, it works correctly,

Expected behavior

The Date response header should parse the obsolete format correctly.

Current behavior

aws.smithy.kotlin.runtime.time.ParseException: parse `Mon, 22 Apr 24 11:57:18 GMT`: error
at 12: expected exactly 4 digits; found 2
at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$takeMNDigitsT$1.invoke(ParserCombinators.kt:180)
at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$takeMNDigitsT$1.invoke(ParserCombinators.kt:168)
at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$preceded$1.invoke(ParserCombinators.kt:294)
at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$preceded$1.invoke(ParserCombinators.kt:292)
at aws.smithy.kotlin.runtime.time.ParsersKt.parseRfc5322(Parsers.kt:301)
at aws.smithy.kotlin.runtime.time.Instant$Companion.fromRfc5322(InstantJVM.kt:109)
at aws.smithy.kotlin.runtime.awsprotocol.ClockSkewInterceptor.modifyBeforeAttemptCompletion-gIAlu-s(ClockSkewInterceptor.kt:88)
at aws.smithy.kotlin.runtime.http.interceptors.InterceptorExecutor.modifyBeforeAttemptCompletion-3t6e044(InterceptorExecutor.kt:263)
at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.tryAttempt-BWLJW6A(RetryMiddleware.kt:86)
at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.access$tryAttempt-BWLJW6A(RetryMiddleware.kt:31)
at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$tryAttempt$1.invokeSuspend(RetryMiddleware.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)\n

Steps to Reproduce

    private suspend fun publishBatch(messages: List<QueueMessage>): List<QueueMessage> {
        val entries = messages.mapIndexed { idx, msg ->
            PublishBatchRequestEntry {
                id = idx.toString()
                message = msg.data
                messageAttributes = msg.messageAttributes()
            }
        }
        return try {
            val resp = client.publishBatch {
                this.topicArn = this@MessageQueuePublisherSns.topicArn
                this.publishBatchRequestEntries = entries
            }
            resp.failed?.mapNotNull { it.id }?.map { messages[it.toInt()] } ?: emptyList()
        } catch (e: aws.smithy.kotlin.runtime.http.HttpException) {
            logger.warn(e) {
                "Failed to publish ${entries.size} messages, errorCode:${e.errorCode} isRetryable:${e.sdkErrorMetadata.isRetryable}"
            }
            messages
        }

Possible Solution

Use correct format for the Date header in the SNS response or allow year to be 2 digits.

Context

No response

AWS Kotlin SDK version used

1.0.31

Platform (JVM/JS/Native)

JVM

Operating System and version

N/A

@schurmann schurmann added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 25, 2024
@ianbotsf
Copy link
Contributor

Thanks for the bug report, @schurmann. I cannot reproduce the error on my end—all the responses I see from SNS include a Date header with 4-digit years (e.g., Thu, 25 Apr 2024 17:41:09 GMT). In which region are you connecting to SNS?

@ianbotsf ianbotsf self-assigned this Apr 25, 2024
@ianbotsf ianbotsf added response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 25, 2024
@schurmann
Copy link
Author

It occurs very rarely for me, so I suspect it will be difficult to reproduce. I'm connecting to eu-central-1 and haven't tried any other regions. When the Date header is correct, it is in the same format as yours.

FYI: I see that the java sdk swallows any parsing exceptions, so there is a difference in behavior. Not sure if that is intended or not.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. label Apr 26, 2024
@ianbotsf
Copy link
Contributor

I still cannot reproduce the bad date responses, even in eu-central-1. If I could then I'd be able to communicate the bad values to the SNS team and hopefully resolve the problem at the source.

That said, the ClockSkewInterceptor shouldn't be breaking on bad server dates. I've opened smithy-lang/smithy-kotlin#1082 to gracefully such handle errors.

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@BastianVoigt
Copy link

BastianVoigt commented Aug 23, 2024

The problem still exists with Smithy 1.3.3 :(
It is now logged as a WARN but still clutters the server logs.
What do you suggest? Should I file a technical support ticket to the SNS team?
What information do you need?

logger: aws.smithy.kotlin.runtime.awsprotocol.ClockSkewInterceptor
message: Service returned malformed "Date" header value "Fri, 23 Aug 24 04:37:17 GMT", skipping skew calculation 
aws.smithy.kotlin.runtime.time.ParseException: parse `Fri, 23 Aug 24 04:37:17 GMT`: error at 12: expected exactly 4 digits; found 2
   at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt.takeMNDigitsT$lambda$6(ParserCombinators.kt:183)
   at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt.preceded$lambda$15(ParserCombinators.kt:297)
   at aws.smithy.kotlin.runtime.time.ParsersKt.parseRfc5322(Parsers.kt:301)
   at aws.smithy.kotlin.runtime.time.Instant$Companion.fromRfc5322(InstantJVM.kt:114)
   at aws.smithy.kotlin.runtime.awsprotocol.ClockSkewInterceptor.modifyBeforeAttemptCompletion-gIAlu-s(ClockSkewInterceptor.kt:90)
   at aws.smithy.kotlin.runtime.http.interceptors.InterceptorExecutor.modifyBeforeAttemptCompletion-3t6e044(InterceptorExecutor.kt:270)
   at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.tryAttempt-BWLJW6A(RetryMiddleware.kt:95)
   at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.access$tryAttempt-BWLJW6A(RetryMiddleware.kt:35)
   at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$tryAttempt$1.invokeSuspend(RetryMiddleware.kt)
   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
   at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
   at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
   at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
   at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants