oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.49k stars 2.71k forks source link

node incompatibility bug: @slack/web-api not resolving promise for webClient.apiCall("apps.connections.open") #8924

Open jozan opened 7 months ago

jozan commented 7 months ago

What version of Bun is running?

1.0.26+c75e768a6

What platform is your computer?

Darwin 23.3.0 x86_64 i386

What steps can reproduce the bug?

this doesn't work in bun but works in node. this is somewhat related to #8310 as we are using the same library but the issue might be different.

import { WebClient, LogLevel } from "@slack/web-api";

const appToken = process.env.SLACK_APP_TOKEN;

const webClient = new WebClient(appToken, {
  logLevel: LogLevel.DEBUG,
});

(async () => {
  try {
    console.log("test open connection");
    const r = await webClient.apiCall("apps.connections.open");
    console.log("result", r);
  } catch (e) {
    console.log("error", e);
  } finally {
    console.log("test open connection finally");
  }
})();

repro steps

most of these steps are just creating a slack bot and obtaining app-level token for it.

  1. clone this repo: https://github.com/jozan/bun-slack-bot

  2. run bun install

  3. go to your slack organization settings page and create a new app. direct link (https://api.slack.com/apps?new_app=1)

  4. select create from manifest and paste this manifest. it will create a bot that has some permissions and has socket mode enabled.

{
    "display_information": {
        "name": "bun-test-bot",
        "description": "desc",
        "background_color": "#0d1f07"
    },
    "features": {
        "bot_user": {
            "display_name": "bun-test-bot",
            "always_online": false
        }
    },
    "oauth_config": {
        "scopes": {
            "bot": [
                "app_mentions:read",
                "channels:history",
                "chat:write"
            ]
        }
    },
    "settings": {
        "event_subscriptions": {
            "bot_events": [
                "app_mention",
                "message.channels"
            ]
        },
        "interactivity": {
            "is_enabled": true
        },
        "org_deploy_enabled": false,
        "socket_mode_enabled": true,
        "token_rotation_enabled": false
    }
}
  1. then install app to your workspace and create app level token in your bot's basic information page and add a require scope
desc img
basic information page image
install to workspace image
generate app level token image
add scope connections:write image
create .env file and put app-level token into it SLACK_APP_TOKEN=xxx
  1. run bun run bun.
  2. alternatively you try check what node does by deleting node_modules and running npm i && npm run node

What is the expected behavior?

this is what node gives us

[DEBUG]  web-api:WebClient:0 initialized
test open connection
[DEBUG]  web-api:WebClient:0 apiCall('apps.connections.open') start
[DEBUG]  web-api:WebClient:0 http request url: https://slack.com/api/apps.connections.open
[DEBUG]  web-api:WebClient:0 http request body: {}
[DEBUG]  web-api:WebClient:0 http request headers: {"Accept":"application/json, text/plain, */*","User-Agent":"@slack:web-api/7.0.2 node/20.11.0 darwin/23.3.0","Authorization":"[[REDACTED]]"}
[DEBUG]  web-api:WebClient:0 http response received
[DEBUG]  web-api:WebClient:0 http request result: {"ok":true,"url":"wss://wss-primary.slack.com/link/?ticket=[[REDACTED]]","response_metadata":{"scopes":["connections:write"],"acceptedScopes":["connections:write"]}}
[DEBUG]  web-api:WebClient:0 apiCall('apps.connections.open') end
result {
  ok: true,
  url: 'wss://wss-primary.slack.com/link/?ticket=[[REDACTED]]',
  response_metadata: {
    scopes: [ 'connections:write' ],
    acceptedScopes: [ 'connections:write' ]
  }
}
test open connection finally

What do you see instead?

the promise never resolves:

$ bun slack.ts
[DEBUG]  web-api:WebClient:0 initialized
test open connection
[DEBUG]  web-api:WebClient:0 apiCall('apps.connections.open') start
[DEBUG]  web-api:WebClient:0 http request url: https://slack.com/api/apps.connections.open
[DEBUG]  web-api:WebClient:0 http request body: {}
[DEBUG]  web-api:WebClient:0 http request headers: {"Accept":"application/json, text/plain, */*","User-Agent":"@slack:web-api/7.0.2 bun/21.6.0 darwin/23.3.0","Authorization":"[[REDACTED]]"}

Additional information

the same code works in node v20.11.0 but not in bun.

jozan commented 5 months ago

some more info why @slack/web-api doesn't work on: https://github.com/oven-sh/bun/issues/8310#issuecomment-2075336600

in short axios maxRedirects: 0 and missing brotli compression are the culprit.

nektro commented 4 months ago

does this still reproduce for you? brotli support was added in Bun 1.1.8 and some http improvements made it into Bun 1.1.9.