Skip to content

uv_write throws when trying to send 3GB over HTTP connection #54225

@simsurace

Description

@simsurace

I encountered some problem JuliaWeb/HTTP.jl#1171 which seems to be an issue in Base when trying to send a large payload over an HTTP connection.

using HTTP

function get_data(::HTTP.Request)
    data = rand(UInt8, 3_000_000_000)
    return HTTP.Response(200, data)
end

const ROUTER = HTTP.Router()
HTTP.register!(ROUTER, "GET", "/", get_data)
server = HTTP.serve!(ROUTER, "127.0.0.1", 8008)

When a request is made, the server throws the error below. The same code works when doing 2GB instead of 3GB.

julia> ┌ Error: handle_connection handler error. 
│ 
│ ===========================
│ HTTP Error message:
│ 
│ ERROR: IOError: write: invalid argument (EINVAL)
│ Stacktrace:
│   [1] uv_write(s::Sockets.TCPSocket, p::Ptr{UInt8}, n::UInt64)
│     @ Base ./stream.jl:1066
│   [2] unsafe_write(s::Sockets.TCPSocket, p::Ptr{UInt8}, n::UInt64)
│     @ Base ./stream.jl:1120
│   [3] unsafe_write
│     @ ~/.julia/packages/HTTP/vnQzp/src/Connections.jl:129 [inlined]
│   [4] unsafe_write(http::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}, p::Ptr{UInt8}, n::UInt64)
│     @ HTTP.Streams ~/.julia/packages/HTTP/vnQzp/src/Streams.jl:95
│   [5] unsafe_write
│     @ ./io.jl:698 [inlined]
│   [6] write(s::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}, a::Vector{UInt8})
│     @ Base ./io.jl:721
│   [7] (::HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
│     @ HTTP.Handlers ~/.julia/packages/HTTP/vnQzp/src/Handlers.jl:61
│   [8] #invokelatest#2
│     @ ./essentials.jl:892 [inlined]
│   [9] invokelatest
│     @ ./essentials.jl:889 [inlined]
│  [10] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Nothing)
│     @ HTTP.Servers ~/.julia/packages/HTTP/vnQzp/src/Servers.jl:469
│  [11] (::HTTP.Servers.var"#16#17"{HTTP.Handlers.var"#1#2"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}}, HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Nothing, ReentrantLock, Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})()
│     @ HTTP.Servers ~/.julia/packages/HTTP/vnQzp/src/Servers.jl:401
└ @ HTTP.Servers ~/.julia/packages/HTTP/vnQzp/src/Servers.jl:483

Tested on

  • Julia 1.10.2
  • HTTP.jl 1.10.5
  • MbedTLS.jl 1.1.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions