Why isn't the server restarting when `FiberHandle.run` is called again?

import * as NodeSocketServer from "@effect/experimental/SocketServer/Node"
import { NodeContext } from "@effect/platform-node"
import { beforeEach, describe, expect, it } from "@effect/vitest"
import { Effect, FiberHandle, Layer, ManagedRuntime, pipe, Scope } from "effect"
import { main } from "../src/main.js"

const rt = ManagedRuntime.make(Layer.empty)

const scope = rt.runSync(Scope.make())
const currenServerFiber = rt.runSync(FiberHandle.make().pipe(Scope.extend(scope)))

const startTestServer = pipe(
  Effect.log("Starting test server"),
  Effect.onInterrupt(() => Effect.log("Interrupted")),
  Effect.zipLeft(main),
  Effect.provide(NodeSocketServer.layer({ port: 9999 })),
  Effect.provide(NodeContext.layer)
)

beforeEach(async () => {
  console.log("beforeEach")
  await pipe(
    Effect.log("hi"),
    Effect.zipLeft(FiberHandle.run(currenServerFiber, startTestServer)),
    rt.runPromise
  )
})

describe("e2e", () => {
  it.effect(
    "test",
    () =>
      Effect.gen(function*() {
        expect(true).toBe(true)
      })
  )
  it.effect(
    "test2",
    () =>
      Effect.gen(function*() {
        expect(true).toBe(true)
      })
  )
})

stdout | test/e2e.test.ts > e2e > test
beforeEach
timestamp=2025-01-29T20:40:31.455Z level=INFO fiber=#4 message=hi

stdout | test/e2e.test.ts > e2e > test2
beforeEach
timestamp=2025-01-29T20:40:31.467Z level=INFO fiber=#33 message=hi

stdout | test/e2e.test.ts
timestamp=2025-01-29T20:40:31.475Z level=INFO fiber=#34 message="Starting test server"
timestamp=2025-01-29T20:40:31.475Z level=INFO fiber=#34 message="Server started" message="{
  \"_tag\": \"TcpAddress\",
  \"hostname\": \"::\",
  \"port\": 9999
}"

 ✓ test/e2e.test.ts (2)
   ✓ e2e (2)
     ✓ test
     ✓ test2

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  15:40:30
   Duration  516ms (transform 36ms, setup 0ms, collect 320ms, tests 19ms, environment 0ms, prepare 30ms)


I am confused why the server isnt getting restarted and interupted when the FiberHandle.run is called a second time?

The FiberHandle docstring looks almost identical and says it will be
Was this page helpful?