dwilhelm89 / Ethermap

Ethermap - A realtime collaborative, version controlled map editor.
Apache License 2.0
124 stars 20 forks source link

Unhandled stream error in pipe. #2

Closed almereyda closed 9 years ago

almereyda commented 9 years ago

Ich benutze Ethermap mit einem selbstgeschriebenen Dockerfile, welches mit einer CouchDB Instanz verlinkt wird:

FROM dockerfile/nodejs-bower-grunt

RUN \
  mkdir -p /data && \
  cd /data && \
  git clone https://github.com/dwilhelm89/Ethermap.git && \
  cd Ethermap && \
  npm install
RUN  \
  cd /data/Ethermap && \
  bower install --allow-root && \
  grunt build

# Define working directory.
WORKDIR /data/Ethermap

ENV NODE_ENV production

# Define default command.
CMD ["node", "dist/server.js"]

Die CouchDB Quelle ist https://github.com/klaemo/docker-couchdb, erstellt mit docker build -t couchdb . gestartet mit docker run -d -p 127.0.0.1::5984 --name="couch_db" couchdb

erstellt mit docker build -t almereyda/ethermap:testing ., gestartet mit docker run -i --name="ethermap" --link couch_db:db -p 8080:3000 almereyda/ethermap:testing

Der Server startet und zeigt auch die Startseite, jedoch das Öffnen einer Map crasht per

info: socket.io started
Express server listening on port 3000 in production mode
GET / 200 15ms
GET /partials/start 200 4ms - 546b
GET /partials/main 200 2ms - 370b
GET /partials/toolbox 200 12ms
{ [Error: error happened in your connection]
  name: 'Error',
  scope: 'socket',
  errid: 'request',
  code: 'ECONNREFUSED',
  errid: 'request',                                                                          [0/1375]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  description: 'connect ECONNREFUSED',
  stacktrace: 
   [ 'Error: connect ECONNREFUSED',
     '    at errnoException (net.js:904:11)',
     '    at Object.afterConnect [as oncomplete] (net.js:895:19)' ] }

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: connect ECONNREFUSED
    at errnoException (net.js:904:11)
    at Object.afterConnect [as oncomplete] (net.js:895:19)

Womöglich ist eine Mitteilung darüber auch in eurem Sentry gelandet; hätte ich gestern Abend doch mal eine eigene Instanz aufgebaut.

Was für ein Fehler kann das sein?

Danke.

almereyda commented 9 years ago

After nsentering the container, it seems not even a simple curl http://localhost:5984/ gives the desired welcome message. Maybe that's the culprit, then.


Well, the linked container is mapped through its alias db in the hosts file, so maybe the db config just needs to be seded. couchdb appears to be a much more appealing alias.


Running the image via docker run -i --name="ethermap" --link couch_db:couchdb -p 8080:3000 almereyda/ethermap:testing after introducing

RUN sed -i 's/localhost/couchdb/' /data/Ethermap/lib/couchdb.js

before the WORKDIR directive in the Dockerfile unfortunately didn't yield any result. It still crashes.

dwilhelm89 commented 9 years ago

I'm not quite sure, but sometimes the 'ECONNREFUSED' occurs if a port is already in use or not accessible. Is there something else running on one of the ports?

almereyda commented 9 years ago

No, it's a direct mapping between the containers. I can also successfully curl the couchdb container from within the ethermap container through

[ root@9ec92a52d01b:/ ]$ curl http://couchdb:5984
{"couchdb":"Welcome","uuid":"123c43544ae5893a53fe5605ee6a1ff1","version":"1.6.1","vendor":{"version":
"1.6.1","name":"The Apache Software Foundation"}}

Therefore I wonder if the Ethermap database has to created first, an admin user has to be created to get the Couch out of Admin party or anything else.


[ root@9ec92a52d01b:/data/Ethermap {master *} ]$ git diff
diff --git a/lib/couchdb.js b/lib/couchdb.js
index 73192a2..932d853 100644
--- a/lib/couchdb.js
+++ b/lib/couchdb.js
@@ -4,7 +4,7 @@
  * @author Dennis Wilhelm
  */

-var nano = require('nano')('http://localhost:5984');
+var nano = require('nano')('http://couchdb:5984');
 var Q = require('q');

 /**

are all resulting changes that happen to be within the Ethermap repository to comply with the linked CouchDB container.


Or did you mean the Express application itself? That's quite impossible, as it runs completely isolated:

[ root@9ec92a52d01b:/ ]$ netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      1/node          
tcp        0      0 0.0.0.0:10843           0.0.0.0:*               LISTEN      1/node          
[ root@9ec92a52d01b:/ ]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.8 669908 32636 ?        Ssl  15:33   0:00 node dist/server.js
root       143  0.0  0.1  19396  4592 ?        S    15:46   0:00 -bash
root       172  0.0  0.0  15576  2220 ?        R+   15:46   0:00 ps aux

I'd like to know which connection is refused and I believe your Sentry may contain entries for that?

dwilhelm89 commented 9 years ago

I guess the error is not related to CouchDB but rather to the http server of node, as the stacktrace reveals errors deep inside the node http modules (net.js, stream.js).

A database connection error should probably occur in 'lib/couchdb.js'.

almereyda commented 9 years ago

I'm directly mapping Node's Port 3000 to a public IP and port 8080. Does the second port, in my case 10843, also have to be reachable publicly or is it proxied through the main Node process?

Maybe the nested-error-stacks npm module may help here.

dwilhelm89 commented 9 years ago

I just tested your docker container resulting in the same error.

However, installing Ethermap natively works without problems. Tested on Ubuntu 12.04 and 14.04 up to the newest node.js version.

So basically I'm not sure what causes this error, but I guess the error is not in the application.

almereyda commented 9 years ago

Let's keep this issue open for now as long as I try to track down the error. A Dockerfile wouldn't be too bad, either.

But did your Sentry instance register any problems? Do I need my own instance? And should error handling be improved, so the server doesn't crash anymore in cases of?

dwilhelm89 commented 9 years ago

The sentry didn't register any errors. It sould only accept errors from my server domain so you don't have to worry about it.

Of course, error handling could be improved!

dwilhelm89 commented 9 years ago

Ok my mistake. Turns out it really is the connection to the database which is failing. However, I still don't know why this is occuring in Docker.

I included a quick fix to prevent the node app from crashing (https://github.com/dwilhelm89/Ethermap/commit/53adc5273b9b3615be5b0465bc92856ff3ea2977) but of course there should be a better errorhandling for non-existent databases ;-)

almereyda commented 9 years ago

You're right. It doesn't crash anymore and I can even use it ( http://ethermap.transformap.co ).

I'm closing this issue, but will open new ones for the new errors I'm experiencing:

almereyda commented 9 years ago

In case if you're interested, I'm now using my own Sentry service https://github.com/14mmm/Ethermap/commit/b313bbd3bef41b2262e2e38e4680495dd6c10898 and will investigate those questions a little further.

almereyda commented 9 years ago

@ubergesundheit Did this work inform your Dockerfile PR anyhow?

ubergesundheit commented 9 years ago

did you update everything?

Before I created the PR, I tested everything on an empty host with just docker and fig installed (see http://128.176.133.116:8081).

What are your errors?

almereyda commented 9 years ago

My live site is down now, but the UI was never loading properly and there were blockers.

Now that your Dockerfile exists, I would love to use it, but your commits didn't contain any updates on the README.

Can I suppose it should work similarily to the following?

Die CouchDB Quelle ist https://github.com/klaemo/docker-couchdb, erstellt mit docker build -t couchdb . gestartet mit docker run -d -p 127.0.0.1::5984 --name="couch_db" couchdb

erstellt mit docker build -t almereyda/ethermap:testing ., gestartet mit docker run -i --name="ethermap" --link couch_db:db -p 8080:3000 almereyda/ethermap:testing

ubergesundheit commented 9 years ago

just use fig ?!

almereyda commented 9 years ago

@ubergesundheit I see. There's the configuration. I always understood fig to be for local deployments only, though. Or do you know of production uses for it?

ubergesundheit commented 9 years ago

I also use it in production. Daemonize with -d Am 18.12.2014 23:51 schrieb "Jon Richter" notifications@github.com:

@ubergesundheit https://github.com/ubergesundheit I see. There's the configuration. I always understood fig to be for local deployments only, though. Or do you know of production uses for it?

— Reply to this email directly or view it on GitHub https://github.com/dwilhelm89/Ethermap/issues/2#issuecomment-67571206.