https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • v

    vans163

    07/27/2021, 5:22 PM
  • v

    vans163

    07/27/2021, 5:23 PM
    it seems I cannot even read 100kb of data before the DO fetch dies
  • v

    vans163

    07/27/2021, 5:23 PM
    Copy code
    javascript
        var view = new Uint8Array(2097152);
        while (1) {
            const { value, done } = await reader.read(view);
            await log_add(this.env, `CHUNK ${value.length} ${done}`)
            if (done) {
                await log_add(this.env, `BRAEK`)
                break;
            }
        }
  • v

    vans163

    07/27/2021, 5:23 PM
    code craps out after reading barely anything, just dies no error
  • v

    vans163

    07/27/2021, 5:28 PM
    hum no ignore it is seems to be working as needed
  • b

    bipolarmorgan

    07/27/2021, 5:28 PM
    wrap it in a try catch and console.log it on error
  • b

    bipolarmorgan

    07/27/2021, 5:28 PM
    ? that might tell you something. just a thought.
  • v

    vans163

    07/27/2021, 5:29 PM
    i was thikning the DO was prematurely dying but it seems not
  • v

    vans163

    07/27/2021, 5:29 PM
    i think its blocking at the very end
  • v

    vans163

    07/27/2021, 5:30 PM
    because done != true
  • v

    vans163

    07/27/2021, 5:30 PM
  • v

    vans163

    07/27/2021, 5:30 PM
    2087453 is the exact # of bytes client transmitted then closed the connection
  • v

    vans163

    07/27/2021, 5:30 PM
    but
  • v

    vans163

    07/27/2021, 5:30 PM
    readablestream BYOB does not mark done == true
  • v

    vans163

    07/27/2021, 5:31 PM
    so we read all bytes but did not get done flag set to true, and we dont know the total size as we are using content-encoding: chunked
  • v

    vans163

    07/27/2021, 5:32 PM
    @User i think this is a bug
  • k

    kenton

    07/27/2021, 5:44 PM
    @User I think your code will throw an exception on the
    done
    message, because
    value
    will be
    undefined
    , so when you try to log
    value.length
    , it'll throw.
  • k

    kenton

    07/27/2021, 5:45 PM
    ohhhh, also, if the client just disconnects without sending a zero-size chunk to terminate the stream cleanly, then
    read()
    itself may throw rather than return a result.
  • k

    kenton

    07/27/2021, 5:46 PM
    From the MDN docs:
  • v

    vans163

    07/27/2021, 5:47 PM
    silly me lol
  • v

    vans163

    07/27/2021, 6:14 PM
    Copy code
    const { readable, writable } = new TransformStream()
          const writer = writable.getWriter()
    
          //writer.write(data)
          //Where does this go?
    
          return new Response(readable, {status: 200})
    is this the correct way to use writable stream response?
  • v

    vans163

    07/27/2021, 6:14 PM
    if we return the new Response can we keep writing to it?
  • v

    vans163

    07/27/2021, 6:16 PM
    basically I want this response to stay open a writer.write gets called over and over (from another request in the DO) and the client should receive chunks of data
  • v

    vans163

    07/27/2021, 6:31 PM
    is there a way to detect writable stream has been closed by the peer?
  • v

    vans163

    07/27/2021, 6:33 PM
  • v

    vans163

    07/27/2021, 6:33 PM
    preferably not a promise
  • v

    vans163

    07/27/2021, 6:33 PM
    (so it can be called every iteration)
  • v

    vans163

    07/27/2021, 6:33 PM
    similar to the websocket closed event
  • v

    vans163

    07/27/2021, 6:33 PM
    or the websocket.state
  • k

    kenton

    07/27/2021, 6:34 PM
    Yes it should be possible to keep it open and write to it over time. I am not sure if there's a way to detect closure. I think probably writing to a stream will throw if the other end is gone? But I'm not sure, you'd have to check the docs and/or try it out.
1...132133134...567Latest