Skip to content

Crash when QNetworkReply is aborted due to timeout #231

@TangJayce

Description

@TangJayce

I'm in China and can't access YouTube without a VPN.
There is a crash problem here.
The call to setTransferTimeout() is bound to crash if it doesn't reply with data within the time set by the parameter.

void MainWindow::on_pushButton_clicked()
{
    fetchData(QString("https://www.youtube.com/"))
    .then([](const QByteArray &bytes) {
        qDebug().noquote() << "fetch data success:" << bytes;
    }, [](const std::exception& e) {
        qDebug() << "fetch data error:" << e.what();
    });
}

QCoro::Task<QByteArray> MainWindow::fetchData(const QUrl &url)
{
    qDebug() << "request:" << url.toString();
    QNetworkRequest request(url);
    // request.setTransferTimeout(10000);
    QNetworkAccessManager manager;
    const auto reply = co_await manager.get(request);
    if (reply->error() != QNetworkReply::NoError) {
        qDebug() << "request error" << reply->errorString();
        co_return {};
    }
    co_return reply->readAll();
}

running environment: Qt_5_15_2_MSVC2019_32bit-Debug

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwindowsWindows/MSVC-specific issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions