websocket: bad handshake with gorilla websockets

i have a websocket server running on railway with a custom domain, and when going to the websocket route in the browser, i get the expected error:

Bad Request
websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header

so i think the server is exposed correctly.

however, when connecting using my cli app with the gorilla websockets package, i get this error:

2023/09/19 18:30:04 websocket: bad handshake
exit status 1

i'm not entirely sure why.

code for connecting:

package client

import (


type StartRequest struct {
    MetaApiKey  string  `json:"META_API_KEY"`
    RiskPercent float64 `json:"RISK_PERCENT"`
    AccountId   string  `json:"ACCOUNT_ID"`
    BrokerSuffix string `json:"BROKER_SUFFIX"`

func Connect() (*websocket.Conn, chan struct{}, error) {
    interrupt := make(chan os.Signal, 1)

    signal.Notify(interrupt, os.Interrupt)

    u := url.URL{Scheme: "ws", Host: os.Getenv("SERVER_HOST"), Path: "/websocket"}


    c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)

    if err != nil {
        return &websocket.Conn{}, make(chan struct{}, 0), err

    done := make(chan struct{}, 1)

    go func() {


    return c, done, nil
have you tried connecting the the websocket server with postman or insomnia?
i haven't
give that a shot
i didn't even know they had websocket support
yep both do!
that's cool
let me know how that goes
server works there just something wrong with the client code
Scheme: "ws"
you need to use wss since railway is https only
oh okay
that did the trick
thank you
no problem!

Looking for more? Join the community!

Recommended Posts
Refund requestHello, I haven't used your service for a while and overlooked the need to unlink my card. Can I pleaHow can I add a json file to my mongoDB with railway?I have a json file containing all of the record my project needs, it is called `sectorA` I want to acould not receive data from client: Connection reset by peerI'm having issues with the DB connection, keep getting: `could not receive data from client: Connectjava.lang.UnsupportedClassVersionErrorHow fix it? I use java 19Add domain to webapp - how?I initially (½ year ago), added my domain under settings - setup the records as described, and it waError adding TCP proxy - Not AuthorizedHello I deployed a service based on a docker image, in order to connect to the service I try to set A way to increase the build timeoutI would like to know if there is a way to increase the build timeout, as I have a very large nextjs TLS handshake timeout during transition from build to deployMy sites have been failing to deploy the whole day + yesterday. I see that this was an issue multiplsave file on file system not foundi've create api to save file to public files after i upload new file on railway host, 404 where i Can I create an environment from a secondary branch of a GitHub repository?Hello, I have a Node.js web app on Railway, and I'm looking for a way to create a second instance fServer becomes unresponsiveCan someone please help me figure out what occurred Saturday? Our production site was not accessibleProject with cron job aways skippedWhy my project nevers run with cronMaximum of 4 volumes per project?Heya 🌞 I have several services and would need to attach another volume to one of these but it get aAny way to skip redeployment if github ci is skipped?Here's what I see on dashboard, railway is granted all accesses in my org on github. On github I caBuild Error after RedeployRecently, I've been facing a weird error whenever I redeploy my railway instance from the dashboard.Restarting database not working.My postgres database wont restart. All data is not modifiy after restaring it.Adding support for python with isolated-vm npm packageHello, I am using a project that requires the isolated-vm npm package (https://www.npmjs.com/packageListmonk; Static FilesNot sure why my post was deleted, but here it is again: Hello, I've deployed Listmonk on Railway, ConcurrencyWill concurrent requests to a single endpoint work? And where would the logs appear for each individProblem with Flask-Caching/ RedisI'm trying to setup a simple caching mecanism to my Plotly Dash (Flask) application deployed to rail