Skip to content

Commit

Permalink
sdk/js: temporarily disable backpressuring for the stream as it cause…
Browse files Browse the repository at this point in the history
…s data to be lost
  • Loading branch information
lithdew committed Jun 13, 2020
1 parent c7ea1cc commit c49f913
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/julienschmidt/httprouter v1.3.0
github.com/lithdew/bytesutil v0.0.0-20200409052507-d98389230a59
github.com/lithdew/kademlia v0.0.0-20200607181215-ff07ba2ac940
github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468
github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3
github.com/stretchr/testify v1.6.0 // indirect
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ github.com/lithdew/monte v0.0.0-20200612162118-d9ef724a278f h1:ePrvQ/QMnHVDjWfan
github.com/lithdew/monte v0.0.0-20200612162118-d9ef724a278f/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc=
github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468 h1:uVJAVZL+BulMCLaRtjVwp4jH2d6IIls+QjkIZdddCvY=
github.com/lithdew/monte v0.0.0-20200612163155-688f7a476468/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc=
github.com/lithdew/monte v0.0.0-20200613022731-a95a5517aea6 h1:pGNp1mgfiRnNTqCxnu7zPna8WT4LFVOoUiiUV5nlEq4=
github.com/lithdew/monte v0.0.0-20200613022731-a95a5517aea6/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc=
github.com/lithdew/monte v0.0.0-20200613030909-f5e1611bfa09 h1:bYiP8Cnf0SU5QHYLfaiRFeI/eFGLKfEPPxjU+VewUjw=
github.com/lithdew/monte v0.0.0-20200613030909-f5e1611bfa09/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc=
github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3 h1:HzVVwsj110ohL9hkXlg0akWmbZLWKnjApiEy0oZao20=
github.com/lithdew/monte v0.0.0-20200613034704-f6d482652dc3/go.mod h1:qisbxmkjwkE+XOLjCiJe+z1U4f95XxF5Hfrk21Rb1yc=
github.com/lithdew/reliable v0.0.0-20200506103725-7df64908b057 h1:CBhKVPym/7ZzY7ascOG93XSTlJuqrmIU/Hd0UDHC1TA=
github.com/lithdew/reliable v0.0.0-20200506103725-7df64908b057/go.mod h1:b9iSDHZ4DaCGpwhQdKsH0u61UancBXJMe0r8SCPKEEA=
github.com/lithdew/seq v0.0.0-20200504083424-74d5d8117a05 h1:j1UtG8NYCupA5xUwQ/vrTf/zjuNlZ0D1n7UtM8LhS58=
Expand Down
4 changes: 3 additions & 1 deletion ts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Flatend {
this.conn.on('data', this._data.bind(this));
this.conn.on('error', console.error);

this.conn.on('close', () => {
this.conn.once('close', () => {
const reconnect = async () => {
console.log(`Trying to reconnect to ${ip.toString(this.id.host, 12, 4)}:${this.id.port}. Sleeping for 1s.`);

Expand All @@ -62,6 +62,8 @@ class Flatend {

console.log(`Successfully connected to ${ip.toString(this.id.host, 12, 4)}:${this.id.port}.`);
} catch (err) {
this.conn.destroy(err);

setTimeout(reconnect, 1000);
}
};
Expand Down
6 changes: 2 additions & 4 deletions ts/monte.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class MonteSocket extends Duplex {
}

async request(req, timeout = 3000) {
const seq = this.counter === 0 ? 1 : this.counter++;
const seq = this.counter === 0 ? 1 : this.counter += 2;
if (this.counter === 2 ** 32) this.counter = 0;

const response = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -218,9 +218,7 @@ class MonteSocket extends Duplex {

if (seq === 0 || this.pending.listenerCount(`${seq}`) === 0) {
try {
if (!this.push({seq, frame})) {
this._paused = true;
}
this.push({seq, frame});
} catch (err) {
this.emit("error", err);
}
Expand Down

0 comments on commit c49f913

Please sign in to comment.