TypeError: This WritableStream is currently locked to a writer

I’m experimenting with cloudflare’s workers to connect to an SMTP server (port 2525 instead of 25). While trying to use multiple writers by closing one before starting another, I always got the error: TypeError: This WritableStream is currently locked to a writer.. What am I doing wrong? This is my code:

export default {
  async fetch(req){
    const addr = { hostname: "mail.domain.example", port: 2525 };

    try {
      const socket = connect(addr, { secureTransport: "starttls", allowHalfOpen: false });
      const encoder = new TextEncoder();

      let encoded = encoder.encode("EHLO examplern");

      const writer1 = socket.writable.getWriter();
      await writer1.write(encoded);
      await writer1.close();

      const writer2 = socket.writable.getWriter();
      await writer2.write(encoded);
      await writer2.close();

    } catch (error) {
      console.log(error);
    }
  }
}

When running this code, it logs the error message. When I run tcpdump on my server, I can see the first EHLO, but not the second one.