Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if randomizationFactor === 0, that will not work! #1231

Closed
1 task done
hookex opened this issue Sep 7, 2018 · 6 comments
Closed
1 task done

if randomizationFactor === 0, that will not work! #1231

hookex opened this issue Sep 7, 2018 · 6 comments

Comments

@hookex
Copy link

hookex commented Sep 7, 2018

You want to:

  • report a bug

Current behaviour

this.randomizationFactor(opts.randomizationFactor || 0.5);

Expected behaviour

if (opts.randomizationFactor === undefined) {
opts.randomizationFactor === 0.5
}

this.randomizationFactor(opts.randomizationFactor);

Setup

  • OS: OSX
  • browser: chrome
  • socket.io version: 2.1.1
@jamesst20
Copy link

This bug is still present as of latest.

The docs says

0 <= randomizationFactor <= 1

But the code does opts.randomizationFactor || 0.5 which makes 0 become 0.5

@darrachequesne
Copy link
Member

Closed due to inactivity, please reopen if needed.

@si458
Copy link

si458 commented Jul 27, 2021

sorry to tag onto this @darrachequesne, but im having this exact issue
if i set randomizationFactor to 0, its being ignore and reset back to 0.5?
my code is as follows

const server = "http://localhost:3000"
const mysocket = io(server, { randomizationFactor: 0, reconnectionDelay: 1000, reconnectionDelayMax: 1000 });

mysocket output is as follows

<ref *1> Socket {
  receiveBuffer: [],
  sendBuffer: [],
  ids: 0,
  acks: {},
  flags: {},
  io: Manager {
    nsps: { '/': [Circular *1] },
    subs: [
      [Function: subDestroy],
      [Function: subDestroy],
      [Function: subDestroy]
    ],
    opts: {
      randomizationFactor: 0,
      reconnectionDelay: 1000,
      reconnectionDelayMax: 1000,
      path: '/socket.io',
      hostname: 'localhost',
      secure: false,
      port: '3000'
    },
    _reconnection: true,
    _reconnectionAttempts: Infinity,
    _reconnectionDelay: 1000,
    _reconnectionDelayMax: 1000,
    _randomizationFactor: 0.5,
    backoff: Backoff { ms: 1000, max: 1000, factor: 2, jitter: 0.5, attempts: 0 },
    _timeout: 20000,
    _readyState: 'opening',
    uri: 'http://localhost:3000',
    encoder: Encoder {},
    decoder: Decoder {},
    _autoConnect: true,
    engine: Socket {
      secure: false,
      hostname: 'localhost',
      port: '3000',
      transports: [Array],
      readyState: 'opening',
      writeBuffer: [],
      prevBufferLen: 0,
      opts: [Object],
      id: null,
      upgrades: null,
      pingInterval: null,
      pingTimeout: null,
      pingTimeoutTimer: null,
      transport: [XHR],
      _callbacks: [Object]
    },
    skipReconnect: false,
    _callbacks: {
      '$open': [Array],
      '$packet': [Array],
      '$error': [Array],
      '$close': [Array]
    }
  },
  nsp: '/',
  connected: false,
  disconnected: true,
  subs: [
    [Function: subDestroy],
    [Function: subDestroy],
    [Function: subDestroy],
    [Function: subDestroy]
  ]
}

@si458
Copy link

si458 commented Jul 27, 2021

i think i found the issue

this.randomizationFactor(opts.randomizationFactor || 0.5);

whats happening is when you set the value to 0, Javascript is deciding 0 is FALSE so revering back to 0.5
proof if you set value to 0.1 that works fine but 0 doesnt work

@si458
Copy link

si458 commented Jul 27, 2021

Also setting reconnectionDelayMax and reconnectionDelay to 0 both also revert to the default values

@si458
Copy link

si458 commented Jul 27, 2021

have submitted patch #1483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants