The Wayback Machine - https://web.archive.org/web/20220124181627/https://github.com/dotnet/aspnetcore/issues/39730
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed assert for m_disconnect_cts->reset() in connection_impl::start #39730

Open
1 task done
gonzo-coder opened this issue Jan 24, 2022 · 0 comments
Open
1 task done

Failed assert for m_disconnect_cts->reset() in connection_impl::start #39730

gonzo-coder opened this issue Jan 24, 2022 · 0 comments

Comments

@gonzo-coder
Copy link

@gonzo-coder gonzo-coder commented Jan 24, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Failed assert for m_disconnect_cts->reset() in connection_impl::start:

void reset()
        {
            std::lock_guard<std::mutex> lock(m_lock);
            assert(m_callbacks.empty());
            m_signaled = false;
            m_callbacks.clear();
        }

This happened then hub_connection disconnects on initial transport failure, for example then server is unavailable, and after that app calls start again, in my case this is a reconnect scenario. See code above.

This happens because in the connection_impl::start_negotiate, around 202th line, m_disconnect_cts is not canceled like in the connection_impl::shutdown.

Expected Behavior

No response

Steps To Reproduce

This can be added to tests in the main project, assertion will fail:

TEST(start, propogates_exception_from_negotiate_and_starts_again)
{
    auto http_client = std::make_shared<test_http_client>([](const std::string& url, http_request, cancellation_token) -> http_response
        {
            throw custom_exception();
        });

    auto websocket_client = create_test_websocket_client();
    auto hub_connection = hub_connection_builder::create("http://fakeuri")
        .with_logging(std::make_shared<memory_log_writer>(), trace_level::none)
        .with_http_client_factory([http_client](const signalr_client_config& config)
            {
                http_client->set_scheduler(config.get_scheduler());
                return http_client;
            })
        .with_websocket_factory([websocket_client](const signalr_client_config&) { return websocket_client; })
        .build();

    auto mre = manual_reset_event<void>();
    hub_connection.start([&mre](std::exception_ptr exception)
        {
            mre.set(exception);
        });

    try
    {
        mre.get();
        ASSERT_TRUE(false);
    }
    catch (const custom_exception& e)
    {
        ASSERT_STREQ("custom exception", e.what());
    }

    hub_connection.start([&mre](std::exception_ptr exception)
        {
            
        }); ///<-------- here assertion fails

    ASSERT_EQ(connection_state::disconnected, hub_connection.get_connection_state());
}

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants