ngx.var.upstream_* variables are not populated when using lua-resty-websocket

オープン
#96 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
lua, nginx

調査の方向性

まず resty.websocket.client エントリポイントと再現手順に示されている client:connect 呼び出しから始め、Lua で作成された upstream 接続が、列挙されている ngx.var.upstream_* 値とどのように関係するかを調べます。ws://127.0.0.1:9001/ws に対する nil 値を再現します。issue では hooks、ngx.ctx メトリクス、upstream トラッキングが代替案として提示されているため、完了条件は具体的に定義されていません。

索引モデルが issue の本文から書いたものです。

説明

🐛 Bug Report: ngx.var.upstream_* variables are not populated when using lua-resty-websocket

Module: [openresty/lua-resty-websocket](https://github.com/openresty/lua-resty-websocket)
Problem: When using lua-resty-websocket to initiate a WebSocket connection to an upstream server manually, all of the following variables are missing or always nil:

ngx.var.upstream_addr
ngx.var.upstream_response_time
ngx.var.upstream_connect_time
ngx.var.upstream_header_time
ngx.var.upstream_bytes_received
🔍 Expected Behavior

These upstream-related variables should be available (or have an alternative way to be collected) so that access logs and metrics are still meaningful, even when the upstream connection is established in Lua.

📋 Actual Behavior

All upstream-related variables return nil or are completely unset:

ngx.log(ngx.ERR, ngx.var.upstream_addr)              -- nil
ngx.log(ngx.ERR, ngx.var.upstream_response_time)     -- nil
ngx.log(ngx.ERR, ngx.var.upstream_connect_time)      -- nil
ngx.log(ngx.ERR, ngx.var.upstream_header_time)       -- nil
ngx.log(ngx.ERR, ngx.var.upstream_bytes_received)    -- nil
📎 Context

We are using lua-resty-websocket to implement a WebSocket reverse proxy behavior with dynamic upstream selection and load balancing (e.g., round-robin / ip-hash in Lua). But since the upstream connection is made via Lua (and not via proxy_pass), OpenResty doesn’t populate any of the $upstream_* variables in access logs, which makes it difficult to monitor or troubleshoot.

✅ Suggestion

Even if these variables cannot be automatically populated, perhaps the library could expose hooks or utility functions to manually record metrics into ngx.ctx, or better integration with OpenResty’s upstream tracking mechanism (if possible).

🧪 Steps to Reproduce
local wb = require("resty.websocket.client")
local client, err = wb:new()
local ok, err = client:connect("ws://127.0.0.1:9001/ws")
-- Send/receive some data...
ngx.log(ngx.ERR, ngx.var.upstream_addr) -- nil
主要言語
Lua
スター
524
フォーク
112
平均マージ
1時間 20分
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openresty/lua-resty-websocket のほかの issue

openresty/lua-resty-websocket の issue をすべて見る

似ている issue

Lua の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。