firebase / firebase/firebase-tools

Random Http2Exception exception when running Firestore emulator with Bun

Open
#8,226 0 comments 0 reactions 0 assignees View on GitHub
emulators: firestore type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

> It's minor bug

### Environment info

**firebase-tools:** 13.31.1
**Platform:** Sequoia 15.3.1
**Bun:** 1.2.2
**Java:** 23.0.2
**firebase-admin**: 13.1.0

### Test case

When running several test calling **Firestore emulator** with **Bun** a `io.netty.handler.codec.http2.Http2Exception` appear randomly. Same with my Github action. Running command: `firebase emulators:exec --only firestore 'bun test'`

```ts
// src/bug.test.ts

import { afterEach, beforeAll, describe, expect, it } from 'bun:test'
import { type RulesTestEnvironment, initializeTestEnvironment } from '@firebase/rules-unit-testing'
import { getApps, initializeApp } from 'firebase-admin/app'
import { type Firestore, getFirestore } from 'firebase-admin/firestore'

let testEnv: RulesTestEnvironment
let db: Firestore
beforeAll(async () => {
testEnv = await initializeTestEnvironment({})
db = getFirestore(getApps()[0] ?? initializeApp())
})

afterEach(async () => {
await testEnv.clearFirestore()
})

describe('Firestore emulator', () => {
it('Bug', async () => {
// Given
await db.collection('transactions').doc('001').set({ id: '001', amount: 100 })
await db.collection('transactions').doc('002').set({ id: '002', amount: 200 })

// When
const transactions = (await db.collection('transactions').get()).docs

// Then
expect(transactions.length).toBe(2)
})
})
```

### Steps to reproduce

Run the command `firebase emulators:exec --only firestore 'bun test src/bug.test.ts --rerun-each 50'` using the test above.

### Expected behavior

Should not have this error.

### Actual behavior

```log
# Outputs tests logs
...
src/bug.test.ts: (run #15)
✓ Firestore emulator > Bug [9.54ms]

# Unhandled error between tests
-------------------------------
2186 | }
2187 | constructor(url, options, listener) {
2188 | super();
2189 | if (typeof url === "string")
2190 | url = new URL(url);
2191 | throw @makeErrorWithCode(21, "Invalid URL");
^
TypeError: The "Invalid URL" argument must be of type undefined. Received undefined
at new ClientHttp2Session (node:http2:2191:50)
-------------------------------

src/bug.test.ts: (run #16)
✓ Firestore emulator > Bug [13.58ms]

src/bug.test.ts: (run #17)
✓ Firestore emulator > Bug [9.78ms]
...
```

```log
# firestore-debug.log

Feb 18, 2025 1:00:23 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://127.0.0.1:9150
API endpoint: http://127.0.0.1:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080

If you are running a Firestore in Datastore Mode project, run:

export DATASTORE_EMULATOR_HOST=127.0.0.1:8080

Note: Support for Datastore Mode is in preview. If you encounter any bugs please file at https://github.com/firebase/firebase-tools/issues.
Dev App Server is now running.

Feb 18, 2025 1:00:23 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Feb 18, 2025 1:00:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
Feb 18, 2025 1:00:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
Feb 18, 2025 1:00:24 PM io.grpc.netty.NettyServerTransport notifyTerminated
INFO: Transport failed
io.netty.handler.codec.http2.Http2Exception: Stream 8552448 does not exist for inbound frame WINDOW_UPDATE, endOfStream = false
at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:107)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.verifyStreamMayHaveExisted(DefaultHttp2ConnectionDecoder.java:697)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onWindowUpdateRead(DefaultHttp2ConnectionDecoder.java:619)
at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onWindowUpdateRead(Http2InboundFrameLogger.java:124)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readWindowUpdateFrame(DefaultHttp2FrameReader.java:596)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:268)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:164)
at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:39)
at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder.decodeFrame(DefaultHttp2ConnectionDecoder.java:187)
at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:391)
at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:451)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1407)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:918)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:1575)

Feb 18, 2025 1:00:24 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected HTTP/2 connection.
*** shutting down gRPC server since JVM is shutting down
*** server shut down
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.