KotlinJS Ktor server "Connection closed without response" when deployed to Heroku - kotlin

I'm new to kotlin and having some trouble running my Ktor server on heroku
I'm setting up the server as follows:
val port = System.getenv("PORT")?.toInt() ?: 9090
embeddedServer(Netty, port = port) {
routing {
get("/") {
call.respondText(
this::class.java.classLoader.getResource("index.html")!!.readText(),
ContentType.Text.Html
)
}
static("/static") {
resources("")
}
}
}.start(wait = true)
When running on my localhost, this responds just fine. And when running in heroku, I get the log output that tells me it did start up the server on the port heroku defines:
[main] INFO ktor.application - Responding at http://0.0.0.0:55278
But then when I try to load the heroku app from the browser, I get an error, and the heroku logs say: "Connection closed without response"
heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=melomidi.herokuapp.com request_id=e0cdaa83-eaa4-4733-a51f-947de463c433 fwd="174.246.82.169" dyno=web.1 connect=0ms service=13ms status=503 bytes=0 protocol=http
I have tried with both http and https. I have also tried loading /static/index.html directly and got the same result.
I've also tried adding a SERVER_HOST env var and using that to change the default 0.0.0.0 host to various things, like localhost, 127.0.0.1 and melomidi.herokuapp.com but those resulted in other errors where the server failed to start up.
There are no other details or additional logs being output in the heroku logs when I make the request. Just the one error line per request as displayed above.
Anyone have any suggestions? Thanks in advance!

After shuffling the order of operations around so that my static resources declaration came first, I started seeing the following error in the logs:
2022-01-08T00:19:36.616138+00:00 app[web.1]: Caused by: java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
2022-01-08T00:19:36.616138+00:00 app[web.1]: at io.ktor.utils.io.jvm.javaio.ReadingKt$toByteReadChannel$1.invokeSuspend(Reading.kt:53)
2022-01-08T00:19:36.616138+00:00 app[web.1]: at io.ktor.utils.io.jvm.javaio.ReadingKt$toByteReadChannel$1.invoke(Reading.kt)
2022-01-08T00:19:36.616139+00:00 app[web.1]: at io.ktor.utils.io.jvm.javaio.ReadingKt$toByteReadChannel$1.invoke(Reading.kt)
2022-01-08T00:19:36.616139+00:00 app[web.1]: at io.ktor.utils.io.CoroutinesKt$launchChannel$job$1.invokeSuspend(Coroutines.kt:132)
2022-01-08T00:19:36.616139+00:00 app[web.1]: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-01-08T00:19:36.616139+00:00 app[web.1]: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2022-01-08T00:19:36.616139+00:00 app[web.1]: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
2022-01-08T00:19:36.616140+00:00 app[web.1]: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
2022-01-08T00:19:36.616140+00:00 app[web.1]: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
2022-01-08T00:19:36.616140+00:00 app[web.1]: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
That got me to this post:https://youtrack.jetbrains.com/issue/KTOR-3358 where I found there is a binary compatibility issue with Ktor server 1.6.5 and jdk 1.8
I updated my jvmTarget to 11 and now it's up and running!
Strange that I only encountered the issue on heroku though when both my localhost and heroku were each using jdk 1.8 previously.

Related

Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)

I'm trying to make edits to certain pages on our website on localhost:3000 but am experiencing the following error on specific pages.
Redis::CannotConnectError in FeaturesController#inventory
Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
ENV dump:
GATEWAY_INTERFACE: "CGI/1.2"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate, sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CACHE_CONTROL: "max-age=0"
REMOTE_ADDR: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
In development.log file, it says:
Started GET "/en/ipad-pos-for-retail/inventory-management" for 127.0.0.1 at 2016-10-05 17:02:22 -0400
Processing by FeaturesController#inventory as HTML
Parameters: {"locale"=>"en"}
Geokit is using the domain: localhost
Completed 500 Internal Server Error in 709ms
Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
app/controllers/features_controller.rb:46:in `inventory'
Rendered /Users/benedictwong/.rvm/gems/ruby-2.2.5/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (10.4ms)
Rendered /Users/benedictwong/.rvm/gems/ruby-2.2.5/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.4ms)
Rendered /Users/benedictwong/.rvm/gems/ruby-2.2.5/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (45.1ms)
Would really appreciate some help! Complete newbie here!

Watir-webdriver can't access 127.0.0.1

I receive a "Gateway Timeout" error when running the following ruby code using watir-webdriver.
require 'watir-webdriver'
browser = Watir::Browser.new :ff
The error states:
Server error - server 127.0.0.1 is unreachable at this moment.Please retry the request or contact your adminstrator.
I have a feeling the company proxy is interfering with Watir. Maybe Firefox is trying to connect to Watir running locally on some non-standard port, and the proxy intervenes and can't resolve the address 127.0.0.1. That's just a guess.
Anyone have experience with this error or suggestions for getting watir-webdriver working. Has anyone successfully run watir-webdriver behind a proxy?
Here is the error with stack trace:
504 Gateway Timeout
Gateway Timeout Server error - server 127.0.0.1 is
unreachable at this moment.Please retry the request or contact
your admins trator.
(Selenium::WebDriver::Error::WebDriverError)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:66:in
create
_response' C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/default.rb:66:in
reque st'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:40:in
call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:640:in
raw_execut e'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:101:in
create_ses sion'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:68:in
initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/firefox/bridge.rb:36:in
initialize '
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:31:in
new'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:31:in
for'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver.rb:67:in
for'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:46:in initialize' c:/dev/pxmapper/features/support/env.rb:11:innew'
c:/dev/pxmapper/features/support/env.rb:11:in <top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/rb_support/rb_language.rb:95:in
load'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/rb_support/rb_language.rb:95:in
load_code_file'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:180:inload_file'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:83:in
block in load_files!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:82:in
each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime/support_code.rb:82:in
load_files!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime.rb:184:in
load_step_definitions'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime.rb:42:in
run!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/lib/cucumber/cli/main.rb:47:in
execute!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.18/bin/cucumber:13:in
<top (required)>' C:/Ruby193/bin/cucumber:23:inload'
C:/Ruby193/bin/cucumber:23:in `'

Omniauth issue with Heroku

I implemented omniauth to allow users to login via Twitter. Everything works smooth on my local environment. However, after pushing to Heroku I get an error. The error appears after the redirect to Twitter and after I click to authorize the app. Can anyone point me in the right direction?
Heroku logs:
2014-12-06T22:54:36.173266+00:00 app[web.1]: Started GET "/auth/twitter/callback?oauth_token=0YwVXdIdacx8lK2g31xgtYN5PJzBrthV&oauth_verifier=6gYtUY1sHAimjOPQ2P9FBWqkG4t85wf1" for 207.62.246.40 at 2014-12-06 22:54:36 +0000
2014-12-06T22:54:36.179194+00:00 app[web.1]: I, [2014-12-06T22:54:36.178840 #2] INFO -- omniauth: (twitter) Callback phase initiated.
2014-12-06T22:54:36.784626+00:00 app[web.1]: Processing by SessionsController#create as HTML
2014-12-06T22:54:36.784637+00:00 app[web.1]: Parameters: {"oauth_token"=>"0YwVXdIdacx8lK2g31xgtYN5PJzBrthV", "oauth_verifier"=>"6gYtUY1sHAimjOPQ2P9FBWqkG4t85wf1", "provider"=>"twitter"}
2014-12-06T22:54:36.801839+00:00 app[web.1]: Completed 500 Internal Server Error in 17ms
2014-12-06T22:54:36.805144+00:00 app[web.1]:
2014-12-06T22:54:36.805147+00:00 app[web.1]: NameError (undefined local variable or method `omniauth' for #<Class:0x007f88aa8b7c90>):
2014-12-06T22:54:36.805149+00:00 app[web.1]: app/models/user.rb:11:in `block in create_with_omniauth'
2014-12-06T22:54:36.805150+00:00 app[web.1]: app/models/user.rb:7:in `create_with_omniauth'
2014-12-06T22:54:36.805152+00:00 app[web.1]: app/controllers/sessions_controller.rb:4:in `create'
2014-12-06T22:54:36.805154+00:00 app[web.1]:
2014-12-06T22:54:36.805155+00:00 app[web.1]:
2014-12-06T22:54:36.808588+00:00 heroku[router]: at=info method=GET path="/auth/twitter/callback?oauth_token=0YwVXdIdacx8lK2g31xgtYN5PJzBrthV&oauth_verifier=6gYtUY1sHAimjOPQ2P9FBWqkG4t85wf1" host=www.insidertees.com request_id=c242efb5-8070-4bea-848e-b5542dcf79f1 fwd="207.62.246.40" dyno=web.1 connect=2ms service=638ms status=500 bytes=1754
Dumb mistake. Change omniauth to auth. Issue solved.

RefineryCMS routes for Home page doesn't work

just started with RefineryCMS, sorry for newbie question. It runs fine locally and deployed luckily on Heroku Cedar stack. Created a page called Home. /pages/home responds fine.
routes.rb
root :to => 'pages#home'
and works on localhost:3000 but on Heroku it gives error.
The app is here:
http://refkocedar.herokuapp.com/home works
http://refkocedar.herokuapp.com/ does not work
How to set Home page to root on Heroku? Thanks for help!
$ heroku logs
2012-04-03T02:19:57+00:00 heroku[router]: GET refkocedar.herokuapp.com/assets/application-ddce3db0fc667014faf95d85d24c71d4.js dyno=web.1 queue=0 wait=0ms service=4ms status=304 bytes=0
2012-04-03T02:19:58+00:00 heroku[router]: GET refkocedar.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=4ms status=304 bytes=0
2012-04-03T02:19:58+00:00 app[web.1]: cache: [GET /favicon.ico] miss
2012-04-03T02:20:04+00:00 app[web.1]:
2012-04-03T02:20:04+00:00 app[web.1]:
2012-04-03T02:20:04+00:00 app[web.1]: Started GET "/" for 80.98.142.244 at 2012-04-03 02:20:04 +0000
2012-04-03T02:20:04+00:00 app[web.1]: cache: [GET /] miss
2012-04-03T02:20:04+00:00 app[web.1]: cache: [GET /] miss
2012-04-03T02:20:04+00:00 app[web.1]: cache: [GET /] miss
I was trying Refinery recently on myocal workspace and had a similar issue. Not sure what is different on heroku as I didnt try anything on it. This solution worked for me.
http://groups.google.com/group/refinery-cms/browse_thread/thread/504b72ec2f1575d5
Refinery admin page you have a option as "forward this page" under advanced options. Set "/"
Here I explain step by step how to set up your home as root_path(localhost:3000).
go to http://localhost:3000/refinery/login
1.Then Login with your username and password.
2.Click to Pages
3.click edit link which page you want to see when localhost:3000 loaded.
4.Click Advanced Options
5.Set / in Forward this page to another website or page text box. Then click Save
6.Now your home page will show on localhost:3000
What Sonu linked to from google groups is correct. You need to add the following in your routes.rb:
root :to => 'pages#home'
And then change the setting on your home page (under advanced settings) that says:
Forward this page to another website or page
and have this forwarded to /
This worked for me.
Very short answer. Under "Advanced Options", set "Forward this page to another website or page" to /
It doesn't sound like it should work, but it does.
I'd say this is almost certainly an error with your routes.rb file.
I was working through the Rails Tutorial by Michael Hartl to setup my new app and ran into this error over and over again.
Check to make sure that Heroku knows the correct root path e.g. " root 'application#hello'"

Rails 3 Routing Error after Redeploy

I'm hosting a Rails 3 site on Heroku, and I've found that whenever I push a new release, POST requests raise a RoutingError until the user clears his cookies. I don't have any problems while developing locally; just when I push to Heroku. So you can hit the front page, but you get a RoutingError when you submit the Sign Up and Log In forms. Has anyone else seen this behavior? Any ideas how to fix it?
I really don't think the problem here is my config/routes.rb or in my controllers/views, because normally this works, but it breaks when I push a new release, at least until cookies get cleared. Could this be a protect_from_forgery issue?
If it helps, here are my logs:
2011-08-29T16:42:30+00:00 heroku[router]: POST mysite.com/signup dyno=web.1 queue=0 wait=0ms service=354ms status=200 bytes=7518
2011-08-29T16:42:30+00:00 heroku[nginx]: 128.91.71.89 - staging [29/Aug/2011:09:42:30 -0700] "POST /signup HTTP/1.1" 200 2482 "http://mysite.com/" "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0" mysite.com
2011-08-29T16:43:17+00:00 app[web.1]:
2011-08-29T16:43:17+00:00 app[web.1]:
2011-08-29T16:43:17+00:00 app[web.1]: Started POST "/signup" for 128.91.71.74 at Mon Aug 29 09:43:17 -0700 2011
2011-08-29T16:43:17+00:00 app[web.1]:
2011-08-29T16:43:17+00:00 app[web.1]: ActionController::RoutingError (No route matches "/signup"):
Well, it turns out the problem was the login & signup forms were doing a PUT, not a POST, because #user was wrongly getting set under certain weird conditions. Sorry to waste the time of anyone who bothers reading this!