snowflakedb / snowflake-connector-net

Snowflake Connector for .NET
Apache License 2.0
173 stars 130 forks source link

SNOW-1276398: OpenAsync does not throw an exception in case of timeout #900

Open vc-74 opened 3 months ago

vc-74 commented 3 months ago
  1. What version of .NET driver are you using? 3.0.0

  2. What operating system and processor architecture are you using? Windows Server 2019 X64

  3. What version of .NET framework are you using? .net8

  4. What did you do? In the connection string, if a proxy is specified but cannot be reached, OpenAsync times out (as expected) but no exception is thrown resulting in a connection which State is Closed.

string connectionString = "...;useproxy=true;proxy;proxyhost=unreachable;proxyport=4000";
using SnowflakeDbConnection connection = new(connectionString);
await connection.OpenAsync().ConfigureAwait(false);

// connection is Closed and no exception has been thrown
  1. What did you expect to see?

    An exception should be raised in case the connection cannot be opened.

  2. Can you set logging to DEBUG and collect the logs?

    Not relevant.

  3. What is your Snowflake account identifier, if any? (Optional)

sfc-gh-dszmolka commented 3 months ago

hi and thank you for raising this with us. So I'm trying to reproduce the problem using .NET Core 6.0 (which is supported by the driver) and Snowflake.Data v3.0.0 and this repro program:

using System.Data.Common;
using Snowflake.Data.Client;

class Program
{
    static async Task Main(string[] args)
    {
        string connectionString = "account=myaccount.eu-central-1; " +
                               " user=admin; password=password; role=ACCOUNTADMIN;" +
                               " DB=TEST_DB; warehouse=COMPUTE_WH;" +
                               " useproxy=true;proxyhost=no.such.pro.xy;proxyport=8080";
        try
        {
            await ConnectToSnowflakeAsync(connectionString);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error connecting to Snowflake: {ex.Message}");
        }
    }

    static async Task ConnectToSnowflakeAsync(string connectionString)
    {
        using (var connection = new SnowflakeDbConnection())
        {
            connection.ConnectionString = connectionString;

            await connection.OpenAsync().ConfigureAwait(false);

            Console.WriteLine("Connected to Snowflake!");

            await ExecuteQueryAsync(connection, "SELECT current_timestamp()");

            await connection.CloseAsync();
        }
    }

    static async Task ExecuteQueryAsync(DbConnection connection, string query)
    {
        using (var command = connection.CreateCommand())
        {
            command.CommandText = query;

            using (var reader = await command.ExecuteReaderAsync())
            {
                while (await reader.ReadAsync())
                {
                    Console.WriteLine($"Current Timestamp: {reader[0]}");
                }
            }
        }
    }
}

and what I'm seeing after running the program, that it gets hung for ~1.5 minutes, then bails out with

Connected to Snowflake!
Error connecting to Snowflake: Error: Executing command on a non-opened connection. SqlState: , VendorCode: 270059, QueryId:

so I could not get to the 'no exception is thrown' ; i'm getting an error after all. Without the non-existing proxy part, the query is successfully run.

if you're seeing something different, could you please provide us with a minimal viable and runnable code which when run, leads to the issue you're experiencing?

vc-74 commented 3 months ago

so I could not get to the 'no exception is thrown' ; i'm getting an error after all. Without the non-existing proxy part, the query is successfully run.

You actually did, the exception is thrown by ExecuteQueryAsync, not OpenAsync. You did not include the stack trace but it's probably what it says. I would expect OpenAsync to throw the exception instead.

sfc-gh-dszmolka commented 3 months ago

ah - you're right. Got you now. We'll take a look - thanks for drawing our attention to this one !

vc-74 commented 2 months ago

@sfc-gh-dszmolka Hi, any ETA for the resolution of this issue? Thanks

sfc-gh-dszmolka commented 2 months ago

hey - no fixed ETA known at this moment but i'm syncing internally on this one and will update this thread once I got any estimated delivery. (to set the expectations: the very earliest possible is at the end of this month with the April release cycle, if we fall outside of that, then in the May release cycle)

will post the further details once known - thank you for bearing with us !

vc-74 commented 2 months ago

Thanks. I have a related question: does the connector only take the specified proxy parameters into account, or does it also take the user/system configured proxy into account?

sfc-gh-dszmolka commented 2 months ago

the supported way of specifying the proxy is to use USEPROXY & co. as described in the README, specified in the connection string.

I never tested with the system-wide envvars like HTTP_PROXY / HTTPS_PROXY so it might or might not work, need to test it. Specifying the proxy as .pac file, should not work (for any of the Snowflake drivers)

vc-74 commented 2 months ago

I don't think these environment variables are taken into account but it seems like even when I specify a proxy manually, my WinInet configuration is used.

sfc-gh-dszmolka commented 2 months ago

if you wish to discuss this second topic (on the proxy) further or even suspect there is a bug, could you please raise a separate Issue for it ? Seems a bit unrelated to the original issue which revolves around how OpenAsync behaves and allows dependent queries to proceed (and surely fail) instead of failing fast.

vc-74 commented 2 months ago

You're right, thanks