Commit Graph

68 Commits

Author SHA1 Message Date
Ben Davies
b66e395bf6 Add Config.ofe, refactor optional dependency usage (#3644)
Config.ofe toggles whether or not to write heapdumps if sockets workers
run out of memory, since ofe is an optional dependency but is not
installed by default. nodemailer is now a nonDefaultDependency, and
will complain if it's not installed when Config.crashguardemail is
enabled.
2017-06-17 14:37:11 -07:00
Ben Davies
d248b652b0 Sockets: make killing workers clean up connections properly (#3645)
If the connections aren't destroyed when the worker is disconnected,
its process will not exit until the remaining connections have closed.
This cleans them up manually so using Sockets.killWorker or
Sockets.killPid does not force any users connected over that worker to
refresh twice in order to reconnect to the server.

This also makes workers respawn automatically after being killed, which
they weren't doing before.
2017-06-16 02:31:44 -05:00
Ben Davies
015dd8db65 REPL: add Config.repl, refactor, Typescript (#3609)
- `Config.repl` enables/disables using REPL sockets since it doesn't
make as much sense to configure whether or not it's enabled with the
REPL_ENABLED const
- exports.start takes a filename parametre rather than a prefix and a
suffix one to avoid having to mutate parametres
- dead REPL sockets are removed from the sockets list when the server
emits an error, and the server closes on error now before respawning
the server
- made the file ready for Typescript
2017-06-11 10:40:38 -05:00
Ben Davies
609bbcdb16 App: do not spawn double the workers when using the launch script (#3534)
app.js already is the main module when using the launch script due to
the way the module's required.
2017-05-18 05:07:13 -05:00
Ben Davies
8de4bdfecb Sockets: refactor to use maps (#3474) 2017-04-23 16:39:38 -07:00
Ben Davies
5031794f97 Sockets: fix unit tests (#3281)
* Sockets: fix Sockets.killWorker not disconnecting connections

* Sockets: fix unit tests

- Fix crash when constructing mock sockets in certain cases
- Properly prevent workers from writing to stdout
- Fix race conditions in workers-related tests that were causing false
  positives

* Tests: mock workers now more closely imitate sockets' workers

This helps catch cases where messages are being sent in the wrong order
to the workers, e.g. messages sent to sockets that no longer exist.
2017-02-24 05:38:37 -06:00
Taylor Everding
1a1f64fe95 Remove .js extension from requires (#2725) 2016-08-30 00:04:40 -05:00
Guangcong Luo
6a60d9de01 Fix bug in 7017029dc1 2016-08-27 01:36:25 -05:00
Guangcong Luo
59e8dc6439 Update client SockJS URL
It was previously entirely wrong! We haven't supported iframes as a
transport for a long time! Unsurprisingly, no one complained since
we don't support particularly old browsers and even old browsers
support JSONP polling...
2016-08-27 01:01:09 -05:00
Guangcong Luo
7017029dc1 Track connection.protocol
This should make it easier to hunt down that bug that's causing SockJS
not to disconnect.

(I have suspicions that it's related to websocket-raw but it's always
nice to get more data...)
2016-08-27 01:01:09 -05:00
Guangcong Luo
e82917fc95 Refactor/merge dnsbl.js and cidr.js
dnsbl.js is kind of a misnomer, but it has been for a long time. It's
currently a collection of various tools useful for IP-based blocking.

Maybe iptools.js?

Anyway, the two files are now one file, and have been refactored a
bit for performance. Dnsbl.query is also a Promise API now.
2016-08-10 15:00:46 -05:00
Guangcong Luo
cd384bb7ce Drop client->server messages over 100KB
These messages are most likely some sort of DDoS; PS doesn't natively
use any messages larger than I think 3KB (is that what teams are?)

server->client messages, on the other hand, can be much longer because
if you join an in-progress battle, PS will send you the entire battle
log up to that point, which can be pretty huge.
2016-06-12 19:58:34 -04:00
小太
e3b014adf0 Remove Config.disablewebsocket
sockjs can't actually disable websockets.
The option actually only disabled the /showdown/websocket address,
which spoke the raw protocol, where the "normal"
/showdown/x/y/websocket address that speaks the sockjs protocol
still worked.
2016-04-17 02:30:39 -07:00
Guangcong Luo
b665660608 Refactor for more ES6 features
Now that nodejs/node#3072 is mostly fixed, we can finally start using
Node 4+ features.

This refactor:

- uses arrow functions where appropriate

  Note that arrow functions still aren't used in Mocha, where `this`
  is sometimes meaningful.

  This also removes the need for .bind() nearly everywhere, as well
  as the `self = this` trick.

- refactors Validator and Connection into ES6 classes

- no longer uses Array#forEach for iterating arrays

  We strongly prefer for (let i = 0; i < arr.length; i++) because of
  performance reasons. Most forEaches have been replaced with for..of,
  though, which is 5x slower than the long-form loop but 2x faster
  than forEach, which is good enough outside of most inner loops.

  The only exception is tournaments, which is due for a more invasive
  refactor soon anyway.
2016-02-10 17:40:21 -06:00
Guangcong Luo
23a83ca6f7 Recover more gracefully from socket worker crashes
Now, instead of exiting PS entirely, we try to respawn the worker
process that crashed.

We also now report the crash with crashlogger.
2016-02-04 03:04:05 -06:00
Guangcong Luo
095652c9ee Exit process when child process exits
If a child process dies in a way that it can't recover from, the main
process now exits, to prevent loops of 'Error: channel closed'
thousands of times a second, filling up the error log and making it
hard to track down the real error.
2016-02-03 22:40:51 -06:00
Guangcong Luo
573922f145 Give more control over when servers are spawned
Previously, include('./sockets.js') and include('./app.js') would
automatically spawn listener processes.

Now, you have to actually use .listen() to spawn listener processes.

This makes the testing framework simpler, since it no longer needs an
ugly hack to suppress spawning socket processes, and also makes it
easier for the ./pokemon-showdown "binary" to pass a port to app.js.

./pokemon-showdown will now also install dependencies if necessary.
2016-01-07 00:20:49 -06:00
Konrad Borowski
81f602b8d8 Always use trailing comma for multiline objects 2016-01-01 00:20:07 +01:00
Guangcong Luo
c5fc8a8030 Fix some minor bugs in battle log retrieval 2015-12-13 02:34:25 -05:00
Guangcong Luo
332a65f9c0 Convert some Users tables to ES6 Maps
Specifically, Users.users, Users.connections, and Users.pastUsers
are now ES6 Maps. In theory, this should be a minor performance
upgrade, but we still need to profile to make sure.
2015-12-10 11:52:26 -05:00
Slayer95
8fd95d8d6f Fix DoS vulnerability in network protocol 2015-11-23 07:49:15 -05:00
Guangcong Luo
a918812201 Remove some unused variables
This cuts down on the number of exceptions for eslint
2015-11-07 23:05:55 -06:00
Ivo Julca
7dddb66253 Migrate build system to ESLint
JSHint's ES6 support is shaky, and its development has stalled as of late.
Since ESLint can do by itself both JSHint and JSCS' jobs, this commit replaces them.
Gulp and its related dependencies are also hereby removed.
2015-11-07 21:36:49 -05:00
Ivo Julca
0479d2b729 Clean up handling of variable bindings in switch statements 2015-11-06 21:58:36 -05:00
Juanma Serrano
c4ac8d6e2f Use strict mode and let and const instead of var
This commit also fixes some duplicated variable declarations.
2015-11-06 21:56:52 -05:00
Ivo Julca
85379ff12e Test: don't listen for connections 2015-09-11 00:38:49 -05:00
Ivo Julca
8cbfea7f69 Crashlogger: include whether the process had an uncaught exception in emails
This is relevant information as some crashes may only happen after some other crash
has created inconsistent state either in PS itself or in Node.js internals.
2015-09-10 22:41:53 -05:00
Guangcong Luo
59e574634b Support an eval message in socket processes
This is intended to be used as a last resort for if a socket process
needs to be hotpatched, and kota's REPL code is too unstable to be
used.

Usage: manually `socket.send('$code')`
2015-08-01 02:56:08 -04:00
Guangcong Luo
1dde0a9473 Some debug code for diagnosing node-static issues 2015-07-21 06:39:10 -04:00
Guangcong Luo
46a5fb0d3b Add diagnostic for obscure crash 2015-06-16 19:12:21 -04:00
Ivo Julca
4222ffb5df Dependant support: make sure that relative paths are resolved properly 2015-05-11 15:38:18 -05:00
Morfent
8adb36508e Remove Heroku hack
The issues Heroku had with SockJS have been fixed for a while since
https://github.com/sockjs/sockjs-node/issues/57, now that it supports
long polling and WebSockets.
2015-04-20 00:42:14 -03:00
Christopher Monsanto
8d87af870f Use 0.0.0.0 if Config.bindaddress is missing.
This is because io.js tries ipv6 first, which the rest of PS does not
support very well.
2015-04-11 22:06:23 -04:00
Ivo Julca
83ffa44e51 Properly fix merge conflict from #1663 2015-03-25 12:17:07 -05:00
Ivo Julca
fe4eb481fa Simplify b6aea81 2015-03-24 14:37:23 -05:00
Guangcong Luo
b6aea81fdf Don't listen on SSL when port overridden
If the port is overridden (either through commandline, test framework,
or environment variable), we probably don't want to listen on any
other port, like the SSL port.
2015-03-23 02:38:09 -04:00
Guangcong Luo
bcadde20e9 Stop telling people to go to 0.0.0.0
Setting Config.bindaddress = '0.0.0.0' (meaning "listen on all IP
addresses") would result in the message "Go to 0.0.0.0:8000 to
test your server" on startup, but 0.0.0.0 is not a valid IP address.

This now says "Go to localhost:8000".
2015-03-20 00:21:20 -04:00
Guangcong Luo
23c67c9140 Quit PS child processes when parent quits
Previously, child processes would stick around in certain cases.

Fixes #1507.
2015-02-05 01:16:47 -06:00
小太
6138ab9e0b Add REPL sockets 2014-12-14 23:11:13 +11:00
Guangcong Luo
018155c9c3 Fix Config.bindaddress
It wasn't getting propagated to socket processes correctly. Also change
the default bind address from 'localhost' to undefined (accept all
connections).
2014-10-29 20:51:00 -04:00
ryanj
3c943fb096 Autoconfiguration for cloud hosting environments, OpenShift support 2014-10-24 23:02:07 -07:00
小太
5027be79fb Add jscs as a style checker, and add some extra jshint options 2014-09-29 18:38:01 +10:00
Guangcong Luo
9bd804838f Implement subchannels
This pushes most of the work of dealing with `|split` from the
main (room) process to the socket process.
2014-08-25 23:48:33 -04:00
Guangcong Luo
12b673bb49 Fix style errors; update gulpfile
I used a hack to make the multiple declaration errors go away,
so all that remained in jsHint were actual errors, which I've
now mostly fixed.

All this linting ended up uncovering one actual bug: Uproar's
message not showing. It's a very minor bug in a move no one uses,
so I'm going to fold it into this commit.
2014-08-10 18:06:44 -04:00
小太
9d0150941b Very minor style fixes 2014-04-28 18:49:09 +10:00
小太
5c8fc7b982 Space after function for anonymous functions 2014-04-22 01:58:16 +10:00
小太
6fb3bc332a Spaces around operators and === instead of == 2014-04-22 01:56:11 +10:00
Slayer95
0126585385 Declare ´channelid´ in sockets´ close event handler 2014-04-17 01:14:15 -04:00
Slayer95
75559362b4 Rename global config to Config 2014-04-17 01:12:28 -04:00
Slayer95
b262316d57 Remove globals defined at sockets.js
App, AppSSL, Server, sweepClosedSocketsInterval and sweepClosedSockets.
2014-04-17 01:10:44 -04:00