Skip to content

Commit

Permalink
Increase OpenID Connect timeouts for Kafka client
Browse files Browse the repository at this point in the history
The authentication was timing out, leading to the Lambda
invocations failing and being retried, which caused duplicate
distributions of GCN Circulars.

See nasa-gcn#2659.
  • Loading branch information
lpsinger committed Dec 6, 2024
1 parent 7409caf commit 6ecf79e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/lib/kafka.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import { Kafka } from 'gcn-kafka'
import memoizee from 'memoizee'
import { custom } from 'openid-client'

import { domain, getEnvOrDieInProduction } from './env.server'

Expand All @@ -18,6 +19,12 @@ const kafka = new Kafka({
domain,
})

function setOidcHttpOptions() {
// Increase the timeout used for OpenID Connect requests.
// See https://github.com/nasa-gcn/gcn.nasa.gov/issues/2659
custom.setHttpOptionsDefaults({ timeout: 10_000 })
}

export let send: (topic: string, value: string) => Promise<void>

// FIXME: A single AWS Lambda execution environment can handle multiple
Expand All @@ -37,6 +44,7 @@ export let send: (topic: string, value: string) => Promise<void>
// testing.
if (process.env.ARC_SANDBOX) {
send = async (topic, value) => {
setOidcHttpOptions()
const producer = kafka.producer()
await producer.connect()
try {
Expand All @@ -49,6 +57,7 @@ if (process.env.ARC_SANDBOX) {
// FIXME: remove memoizee and use top-level await once we switch to ESM builds.
const getProducer = memoizee(
async () => {
setOidcHttpOptions()
const producer = kafka.producer()
await producer.connect()
;['SIGINT', 'SIGTERM'].forEach((event) =>
Expand Down

0 comments on commit 6ecf79e

Please sign in to comment.