localtunnel: Crashing after a few minutes

events.js:85
       throw er; // Unhandled 'error' event
            ^
Error: connection refused: localtunnel.me:37302 (check your firewall settings)
    at Socket.<anonymous> (/usr/local/lib/node_modules/localtunnel/lib/TunnelCluster.js:45:32)
    at Socket.emit (events.js:107:17)
    at net.js:451:14
    at process._tickCallback (node.js:355:11)

I keep getting this error repeatedly on multiple instances of localtunnel but I can’t really pin down what’s causing it. I can’t imagine that the connection is actually getting refused because the tunnel starts up and works normally for however many minutes until it decides to stop working. Is there any way to get it to retry instead of just crashing and closing the tunnel? Right now this is making it really unreliable to use localtunnel because I can’t maintain the connection for any extended period of time.

Thoughts? Solutions?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 20
  • Comments: 45 (4 by maintainers)

Commits related to this issue

Most upvoted comments

ngrok is great, but I’m not paying $5/month just to get custom subdomains.

I use a Ruby script that restarts localtunnel when it crashes (edit: fixed bug that Dave84c pointed out):

require 'optparse'

options = {:subdomain => 'defaultdomain', :port => 3000}

parser = OptionParser.new do|opts|
    opts.banner = "Usage: localtunnel.rb [options]"
    opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain|
        options[:subdomain] = subdomain;
    end

    opts.on('-p', '--port port', 'Port') do |port|
        options[:port] = port;
    end

    opts.on('-h', '--help', 'Displays Help') do
        puts opts
        exit
    end
end

parser.parse!

def ordinal(number)
  abs_number = number.to_i.abs

  if (11..13).include?(abs_number % 100)
    "th"
  else
    case abs_number % 10
      when 1; "st"
      when 2; "nd"
      when 3; "rd"
      else    "th"
    end
  end
end

def ordinalize(number)
  "#{number}#{ordinal(number)}"
end

launch_count = 0

while true
    launch_count += 1
    puts "Running localtunnel for the #{ordinalize(launch_count)} time"
    `lt --port #{options[:port]} --subdomain #{options[:subdomain]}`
end

I’ve been running this for a couple of days, and it’s restarted it 218 times. There must be occasional disruptions, but I haven’t noticed them.

ETA: You’ll need Ruby to run that script. Ruby comes on OSX and on most Linux distributions (not sure about Windows), so it should just run if you save it as a Ruby file. For example, if you save it as localtunnel.rb, you should be able to run it with:

ruby localtunnel.rb --port 3000 --subdomain yourdomainhere

I vote for leaving this issue open until it’s fixed. Closing it makes it seem like localtunnel is more stable than it is. People end up frustrated as a result.

A simple bash script to restart it every time it crashes

#!/bin/bash

function localtunnel { lt -s subdomain --port port_number }

until localtunnel; do echo “localtunnel server crashed” sleep 2 done

+1 for @dreki. Keep this issue open.

Hey @michaelkeenan, I think there is an error in the Code.

opts.on('-s', '--subdomain subdomain', 'Subdomain') do |name| options[:subdomain] = subdomain; end

`opts.on('-p',` '--port port', 'Port') do |age|
    options[:port] = port;
end`

shouldnt the block parameters match the option: name => subdomain, age =>port ?

Cheers, Dave