If the connection to the server is lost while transmission, you will 
probably receive a broken pipe error.
If the timeout happens before sending data, nothing to care.
If the timeout happens during data transmission, well, you may have 
incomplete data(corrupted) in the server.

I don't think there is any way to prevent such thing in the std library 
itself. Your server must be capable to handle state properly, validate what 
it is receiving and decide if it should keep it or not, thus, yes, this is 
all application layer logic.

I think this all relates to how your server will treat idempotence and 
atomic writes. 

On Tuesday, January 3, 2023 at 8:10:03 AM UTC+1 xieyu...@gmail.com wrote:

> Hi, recently I wondered the question about what would happen if http 
> timeout but the request is still sent out.
> The motive is, let's assume we make a post request with a timeout. When 
> timeout, the request is canceled, and the server won't serve it anymore.
>  However, if the request is sent out when timeout, the server actually 
> proceeds it anyway, which may make an unexpected error. 
> So I would like to know how to avoid such an error. Do we need to 
> additional check in the application layer, or could we check it inside the 
> http library?
>
> I triggered the timeout by debugger breakpoint in goland, I set the 
> breakpoint at err = pc.bw.Flush() 
> <https://github.com/golang/go/blob/release-branch.go1.19/src/net/http/transport.go#L2408>
>  in 
> writeLoop and n, err = w.pc.conn.Write(p) 
> <https://github.com/golang/go/blob/release-branch.go1.19/src/net/http/transport.go#L1767>
> .
> In my opinion, the socket is closed once the timeout happens, and the  n, 
> err = w.pc.conn.Write(p) 
> <https://github.com/golang/go/blob/release-branch.go1.19/src/net/http/transport.go#L1767>
>  will 
> always fail as *use of closed network connection*.
> However, the result is it could send out the bytes, I guess it's caused by 
> the debugger, but have no idea about it.
> [image: Image Pasted at 2023-1-3 15-09.png]
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07decabd-a747-48d5-92b4-93d0b88d8eccn%40googlegroups.com.

Reply via email to