Commit Graph

611 Commits

Author SHA1 Message Date
leastbad
d573fb11d7 add connection_identifier to ConnectionStub 2021-06-23 06:19:07 -04:00
Matheus Richard
c3d7794f16 Replace map + compact with filter_map 2021-04-22 22:08:34 -03:00
John Bachir
267e1d25dc Add name to ActionCable threads
To assist in various debugging scenarios, such as [tracking which types of threads are using db connections][0]

Thread names will now be "ActionCable-worker-N" instead of "worker-N".

This is safe for all ruby versions. In versions which do not have thread names, [concurrent-ruby does not attempt to add the name][1]

In the environment I happened to be testing in:

```ruby
e = Concurrent::ThreadPoolExecutor.new(name: 'ActionCable', min_threads: 2, max_threads: 2)
e.post{sleep 100}
e.post{sleep 100}
Thread.list.map(&:name)
```

[0] https://github.com/puma/puma/issues/1512#issuecomment-756760388
[1] https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb#L312
2021-04-14 11:24:37 -07:00
Vladislav
d264276288 RemoteConnection#disconnect: fix ArgumentError on ruby 3.0 2021-04-02 12:24:54 -04:00
Carlos Antonio da Silva
ca06a9ff41 Refactor to use model instead of record as argument in Action Cable
We refer to `model` elsewhere in Action Cable's  implementation, so use
the same in `stream_or_reject_for` as well to keep the consistency.

Simplify the docs for the method to remove the usage "intention"
(that's not up to us) and mention it rejects the "subscription", not
the "connection".
2021-02-25 11:21:19 -03:00
Jonathan Hefner
167f5c8065 Fix inline code markup [ci-skip]
RDoc Markup does not support backticks the way Markdown does to mark up
inline code.  Additionally, `<tt>` must be used to mark up inline code
that includes spaces or certain punctuation characters (e.g. quotes).
2021-02-14 11:20:35 -06:00
Rafael Mendonça França
1b455e2e9d
Rails 6.2 is now Rails 7.0
We have big plans for the next version of Rails and that
require big versions.
2021-02-04 16:47:16 +00:00
Rafael Mendonça França
6487836af8
Rails 7 requires Ruby 2.7 and prefer Ruby 3+
The code cleanup is comming in later commits but this
already remove support to Ruby < 2.7.
2021-02-04 16:34:53 +00:00
Jonathan Hefner
cc9a9e8503 Prevent thundering herd of Action Cable clients
This commit makes a few changes to the Action Cable client to prevent a
"thundering herd" of client reconnects after server connectivity loss:

* The client will wait a random amount between 1x and 3x of the stale
  threshold after the server's last ping before making the first
  reconnection attempt.
* Subsequent reconnection attempts now use exponential backoff instead
  of logarithmic backoff.  To allow the delay between reconnection
  attempts to increase slowly at first, the default exponentiation base
  is < 2.
* Random jitter is applied to each delay between reconnection attempts.

Co-authored-by: John Williams <john@veloshots.com>
2021-02-02 10:43:05 -06:00
alea12
4858c9fa2d Update ActionCable docs [ci skip] 2021-01-08 19:08:55 +09:00
Ryuta Kamizono
2b0b5a75c0 Bump license years to 2021 [ci skip] 2021-01-01 12:21:20 +09:00
Rafael Mendonça França
59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Daniel Colson
d092c133c7
Do not allow subscribing to Base channel
Closes #40482

Prior to this commit it was possible to subscribe with
`ActionCable::Channel::Base` as the subscription class. While it doesn't
seem possible to exploit this in away way, it also doesn't seem like
something we need to allow.

This commit swaps [Module#>=][gte] with [Module#>][gt] to prevent
subscribing to a channel when `ActionCable::Channel::Base` is the
subscription class.

[gte]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E-3D
[gt]: https://ruby-doc.org/core-2.5.3/Module.html#method-i-3E
2020-11-24 22:30:03 -05:00
Jonathan Hefner
949e4587d5 Allow missing Action Cable config
Since #37850, `config_for` returns `nil` instead of an empty Hash when
a config file does not contain configuration for the specified
environment.  Thus, the return value should be converted to a Hash
before calling `with_indifferent_access`.

Fixes #40548.
2020-11-06 11:45:51 -06:00
Rafael Mendonça França
8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Jonathan Hefner
fd3fd618f4 Add gitattributes for vendored and generated files [ci-skip]
The `linguist-vendored` attribute excludes the specified file from the
project's language stats on GitHub.  The `linguist-generated` attribute
does the same, and also suppresses that file in diffs on GitHub.

See https://github.com/github/linguist for more information.
2020-10-04 16:44:37 -05:00
Rafael França
1eade80dd6
Merge pull request #39123 from tannakartikey/actioncable_logger_docs
Added docs for client-side logger
2020-07-06 14:28:43 -04:00
Kartikey Tanna
e0ec24e3c0 Added an example of logging 2020-07-06 23:32:55 +05:30
Ryuta Kamizono
528b62e386 Address to false negative for Performance/DeletePrefix,DeleteSuffix
Follow up to c07dff72278fb7f2a3c4c71212a0773a2b25c790.

Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.

I've checked all those usage and replaced all safe ones.
2020-06-14 13:04:47 +09:00
Tim Craft
7f41ab2b0e Use indifferent access for config hash in actioncable postgresql test 2020-06-10 13:52:43 +01:00
Étienne Barrié
f1cef4c9ca Remove invalid autoloads in top-level Rails modules 2020-06-08 17:21:26 -04:00
Petrik
2b09948637 Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
2020-06-03 08:51:47 +02:00
Kartikey Tanna
c25b77fb6b Added docs for client-side logger 2020-05-03 11:52:06 +05:30
Ryuta Kamizono
592358e182 Update pg gem required version to 1.1
This is required for #39063 to use `PG::TextDecoder::Numeric`.

Ref https://github.com/ged/ruby-pg/pull/25.

The pg gem 1.1.0 was released at August 24, 2018, so I think it is good
timing to bump the required version for improving and cleaning up the
code base.

https://rubygems.org/gems/pg/versions
2020-04-27 16:27:40 +09:00
Liroy Leshed
801716395c
Convert CoffeeScript to ES6 syntax 2020-04-17 14:41:40 +03:00
Abhay Nikam
bdfffd1355 Update the Rails mailing list URLs to new discuss discourse URL [ci skip] 2020-04-02 22:00:28 +05:30
justin talbott
d2571e560c add rescue_with support to ActionCable::Connection::Base
and update ActionCable guide to describe exception handling usage

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# Changes to be committed:
#	modified:   actioncable/CHANGELOG.md
#	modified:   actioncable/lib/action_cable/connection/base.rb
#	modified:   actioncable/lib/action_cable/connection/subscriptions.rb
#	modified:   actioncable/test/connection/subscriptions_test.rb
#	modified:   guides/source/action_cable_overview.md
#
2020-03-20 14:49:38 -07:00
Atul Bhosale
ec69083cf3
Add method ActionCable::Channel#stream_or_reject_for to stream if record is present, otherwise reject the connection (#38375) 2020-03-07 10:09:08 -08:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Zhang Kang
96b74fe433 Introduce ActionCable::Channel#stop_stream_from/for to unsubscribe specific streams (#37171)
* Like `ActionCable::Channel#stop_all_streams`, but for specific streams
2020-01-17 13:39:06 -08:00
alkeshghorpade
aed448cc50 Typo fix of visbility. 2020-01-10 18:59:48 +05:30
Abhay Nikam
d8beb77252 Bump license years from 2019 to 2020 [ci skip] 2020-01-01 15:10:31 +05:30
Carlos Antonio da Silva
3c28e79b61 Fix indent in Action Cable changelog entry [ci skip] 2019-12-31 10:18:55 -03:00
Sergey Ponomarev
723375147b Add ActionCable subscription connection identificator to PostgreSQL adapter
* You can distinguish connection among others with specific `application_name`

    ```sql
    SELECT application_name FROM pg_stat_activity;
    /*
        application_name
    ------------------------
    psql
    ActionCable-PID-42
    (2 rows)
    */
     ```

  * It's possible to customize connection identification with `id` option in `cable.yml`

    `ActionCable-PID-#{$$}` is the default value

  * Related tests refactoring

  * `ActionCable::Server#config.cable` is no mutated anymore inside Redis subscription adapter
2019-12-31 13:23:01 +03:00
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
Eugene Kenny
ee525ff663 Load framework test files in deterministic order
`Dir.glob` doesn't guarantee the order of its results:

https://ruby-doc.org/core-2.6.5/Dir.html#method-c-glob

> Case sensitivity depends on your system (File::FNM_CASEFOLD is
> ignored), as does the order in which the results are returned.

Minitest stores a list of all test cases in the order that they were
defined; it shuffles them before they're run, but doesn't sort them:

https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L1048
https://github.com/seattlerb/minitest/blob/v5.13.0/lib/minitest.rb#L156

This means that the order in which framework tests run is platform
dependent, and running a test command that failed in CI locally won't
necessarily reproduce the error, even when the same seed is provided.

`Rake::FileList` resolves glob patterns to a sorted list of files:

https://github.com/ruby/rake/blob/v13.0.1/lib/rake/file_list.rb#L408

By using `Rake::FileList` instead of `Dir.glob`, framework tests will
always run in the same order when given the same seed, and reproducing
order dependent CI failures will be easier.
2019-12-16 16:55:06 +00:00
Ryuta Kamizono
214f439343 Fixup CHANGELOGs [ci skip] 2019-11-24 09:20:00 +09:00
Dino Maric
966d3a7bf2 Fix typo in ACa documentation [ci skip] 2019-10-28 11:09:22 -04:00
Richard Macklin
fefc304199
Enforce that actioncable compiled JS bundle is in sync with source code
We have run into issues in the past where the actioncable compiled
javascript bundle got out of sync with the source code. For example, in
30a0c7e04093add0b14be6da17c7496e7dd40e10 only the compiled bundle was
modified. This meant that anyone who ran `yarn build` in the actioncable
directory would then see a dirty git status indicating changes to the
compiled bundle, despite not having made any changes to the actioncable
javascript source code. We fixed that particular inconsistency in
a4c27588d5a1e6f270df42b7a305f03a9aee54f2. However, the same problem
could reoccur.

To address this, I've added a new test to enforce that actioncable's
compiled javascript bundle is in sync with the source code. When the
compiled bundle is in sync with the source code, the test will pass:

    $ bundle exec ruby -Itest test/javascript_package_test.rb
    Run options: --seed 19308

    # Running:

    yarn run v1.12.3
    $ yarn lint && bundle exec rake assets:codegen
    $ eslint app/javascript
    $ rollup --config rollup.config.js

    app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
    created app/assets/javascripts/action_cable.js in 762ms
      Done in 6.35s.
    .

    Finished in 7.130345s, 0.1402 runs/s, 0.1402 assertions/s.
    1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

However, if the two are not in sync, the test will fail. For example, if
you were to apply the following patch (which only updates the source
code):

```
diff --git a/actioncable/app/javascript/action_cable/adapters.js b/actioncable/app/javascript/action_cable/adapters.js
index 4de8131438..d38d9a6a0b 100644
--- a/actioncable/app/javascript/action_cable/adapters.js
+++ b/actioncable/app/javascript/action_cable/adapters.js
@@ -1,4 +1,5 @@
 export default {
+  foo: self.foo,
   logger: self.console,
   WebSocket: self.WebSocket
 }
```

the test would then fail like this:

    $ bundle exec ruby -Itest test/javascript_package_test.rb
    Run options: --seed 26377

    # Running:

    yarn run v1.12.3
    $ yarn lint && bundle exec rake assets:codegen
    $ eslint app/javascript
    $ rollup --config rollup.config.js

    app/javascript/action_cable/index.js → app/assets/javascripts/action_cable.js...
    created app/assets/javascripts/action_cable.js in 776ms
      Done in 5.55s.
    F

    Failure:
    JavascriptPackageTest#test_compiled_code_is_in_sync_with_source_code [test/javascript_package_test.rb:16]:
    --- expected
    +++ actual
    @@ -3,6 +3,7 @@
     })(this, function(exports) {
       \"use strict\";
       var adapters = {
    +    foo: self.foo,
         logger: self.console,
         WebSocket: self.WebSocket
       };

    rails test test/javascript_package_test.rb:9

    Finished in 5.837403s, 0.1713 runs/s, 0.1713 assertions/s.
    1 runs, 1 assertions, 1 failures, 0 errors, 0 skips

Thus, the actioncable test suite will now prevent "the compiled bundle
is out of sync" issues going forward.
2019-10-19 02:26:31 +02:00
Orien Madgwick
493edf044f Add bug tracker/documentation/mailing list URIs to the gemspecs 2019-10-11 20:47:19 -04:00
Jean Boussier
a707072ffa Implicitly assert no exception is raised in block assertions 2019-10-07 11:01:24 +02:00
Juanjo Bazán
e4b5a3eb77 update package.json files to use https homepage value 2019-10-02 12:00:11 +02:00
meganemura
3b23c64497 List activesupport as a direct dependency 2019-10-01 13:28:52 -04:00
Narendra Rajput
66a44b1710 Fixed typo in comment in ActionCable::Connection::TestCase [ci skip] 2019-09-24 14:46:36 +05:30
Thomas Fankhauser
66c4861aff Renamed method in documentation string assert_broadcasts_on to the
correct `assert_broadcast_on` to close #37272
2019-09-23 15:30:55 +02:00
Akira Matsuda
8cc1bf9e2b Passing in a Hash instance as non-kwargs parameters has to be curly braced 2019-09-07 03:21:45 +09:00
Akira Matsuda
9a15149dab Keyword arguments is not a Hash 2019-09-07 03:20:07 +09:00
Akira Matsuda
438e93f7fd Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 03:19:51 +09:00
David Heinemeier Hansson
6315a11b90 Logging at info level should be reserved for top-level concerns
Information about partials and cable connection notices are too low level.
2019-08-26 16:43:45 -04:00
Javan Makhmali
55311b1596 Ensure @rails/actioncable package contains complete source
Action Cable's JavaScript library can optionally be imported as an ES6 module via `import { … } from "@rails/actioncable/src"`, but that module is broken in most of the releases published on npm:

```
ERROR in ./node_modules/@rails/actioncable/src/connection.js
Module not found: Error: Can't resolve './internal' in './node_modules/@rails/actioncable/src'
 @ ./node_modules/@rails/actioncable/src/connection.js
 @ ./node_modules/@rails/actioncable/src/index.js
```

Because `internal.js` was gitignored, it would only be included if the publisher happened to have it generated locally. Committing it to version control ensures that won't happen, and gives us better visibility into changes over time.

References:
- https://github.com/rails/rails/pull/34370
- c0368ad090b79c19300a4aa133bb188b2d9ab611
2019-08-15 09:19:59 -04:00