Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Execution stops abruptly during handshake #16

Closed
kinetiq opened this issue Sep 2, 2016 · 5 comments
Closed

Execution stops abruptly during handshake #16

kinetiq opened this issue Sep 2, 2016 · 5 comments

Comments

@kinetiq
Copy link

kinetiq commented Sep 2, 2016

Hi, and thanks for the great work! I'm trying to get this working in a console app, but I'm having a problem. Execution stops abruptly in RequestExecutor.Execute, on this line:

IRestResponse response = await client.ExecutePostTaskAsync(request);

There's no exception that I can detect... I think the await is just never returning - but it doesn't hang, it exits.

I know this is a restsharp call. The key is correct (works in Margibot). Any idea what to try here?

@Workshop2
Copy link
Member

Hey @kinetiq
Do you have a code example anywhere I could try? Are you running through a proxy?

Thanks

@kinetiq
Copy link
Author

kinetiq commented Sep 2, 2016

No proxy, just running this in a simple setup at home.

Code is very simple:

        var connector = new SlackConnector.SlackConnector();
        Connection = await connector.Connect(slackKey);
        Connection.OnMessageReceived += MessageReceived;
        Connection.OnDisconnect += OnDisconnect;

Also! If I go into your code and change this line to synchronous, everything works:

        IRestResponse response = client.ExecuteAsPost(request, "post");

...The handshake succeeds, and I end up getting events and so on! Any idea what this might be?

@Workshop2
Copy link
Member

Is your console app method async? I have seen these kind of issues before when trying to await something when not in an async context.

Could you do something like:

        var connector = new SlackConnector.SlackConnector();
        Connection = connector.Connect(slackKey).Result;
        Connection.OnMessageReceived += MessageReceived;
        Connection.OnDisconnect += OnDisconnect;

@kinetiq
Copy link
Author

kinetiq commented Sep 2, 2016

You are right, I wasn't in an async context! I was doing this:

    static void Main(string[] args)
    {
        MainAsync(args);        
    }

    static async void MainAsync(string[] args)
    {
        var manager = new ConnectionManager();
        await manager.Connect();

        Console.ReadLine();
    }

But I needed to do this:

    static void Main(string[] args)
    {
        MainAsync(args).Wait();
    }

    static async Task MainAsync(string[] args)
    {
        var manager = new ConnectionManager();
        await manager.Connect();

        Console.ReadLine();
    }

Dumb mistake, clearly need to do more async work.

I bet people run into this a lot when they're getting started. I actually bounced off of this problem once before, months ago, and I'm just now playing with it again.

Anyway! Thanks for the help.

@kinetiq kinetiq closed this as completed Sep 2, 2016
@Workshop2
Copy link
Member

No problem, glad to have helped

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants