0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Snowflake 接続が毎回20秒かかる問題の解消

0
Last updated at Posted at 2026-06-05

症状

  • snowflake.connector.connection: Connecting to GLOBAL Snowflake domain というログが出る
  • 接続確立まで毎回ピッタリ20秒かかる
  • ネットワーク自体は問題なし(curl で0.3秒以内に応答)

原因

Snowflake Python Connector の platform detection 機能が原因。

接続時にコネクタが「自分はEC2上で動いているか?Azureか?GCEか?」を確認するために、各クラウドのメタデータエンドポイントに順番にHTTPリクエストを投げる。オンプレ・WSL2環境ではクラウドVMではないため全エンドポイントがタイムアウトになり、その合計が約20秒になる。

DEBUGログで確認すると以下のように記録される:

[DEBUG] snowflake.connector.platform_detection: Platform detection completed.
Detected platforms: ['is_ec2_instance_timeout', 'has_aws_identity',
'is_azure_vm_timeout', 'has_azure_managed_identity_timeout',
'is_gce_vm_timeout', 'has_gcp_identity_timeout']

_timeout サフィックスがついているものはタイムアウトまで待ったことを示す。

platform detection とは

Workload Identity Federation(WIF)という認証方式のための機能。EC2やAzure VMのIAMロールをそのままSnowflakeの認証に使う高度な設定。

JWT認証(SNOWFLAKE_JWT)やパスワード認証を使っている場合は結果が認証に使われないため、スキップしても動作に影響はない。

対処

接続パラメータに platform_detection_timeout_seconds=0 を追加する。

def _build_connect_kwargs() -> dict[str, Any]:
    kwargs: dict[str, Any] = {
        "account": account,
        "host": f"{account}.snowflakecomputing.com",
        "user": user,
        "warehouse": ...,
        "database": ...,
        "client_session_keep_alive": True,
        "platform_detection_timeout_seconds": 0,  # ← これを追加
    }
    return kwargs

0 を指定することでタイムアウト待ちをせず即座にスキップされる。

補足:環境変数での設定

リリースノートには ENV_VAR_DISABLE_PLATFORM_DETECTION という環境変数も記載されているが、接続パラメータで直接指定する方が確実。

対応バージョン

  • platform_detection_timeout_seconds パラメータ:v3.17.2以降で追加
  • 使用確認バージョン:snowflake-connector-python==4.3.0

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?