首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过thinky从Windows 11连接到rethinkdb的问题(nodejs)

通过thinky从Windows 11连接到rethinkdb的问题(nodejs)
EN

Stack Overflow用户
提问于 2022-03-06 17:03:15
回答 1查看 122关注 0票数 2

我正试图加入一个新的开发人员,即使用Windows 11作为我们小组中唯一的开发人员。我指导他安装了WSL2和Ubuntu20.04.3LTS (linux内核:5.10.93.2-MicrosoftStandardWSL 2)。

我们是另外三个分别使用本机Ubuntu、WSL2 Ubuntu21.04和macOS的开发人员。我们都在NodeJS16.14上使用完全相同的package-lock.json文件。

他是唯一一个拿到Error [ERR_STREAM_WRITE_AFTER_END]: write after end的人。

tldr; 这两个错误都是关于写入Buffer的。 有人知道nodejs在Windows11?Buffer上的实现有什么相关问题吗?

我们使用的思辨如下所示:

代码语言:javascript
复制
'use strict';

const createThinky = require('thinky');

const { rethinkdbConfig } = require ('./utils/config.js');

const thinky = createThinky (rethinkdbConfig);

// Thinky is our ORM
var type = thinky.type;

// Creates the thinky DB model for payments - we save the amount and the stripe customerID for each transaction
// You can execute any rethinkdb query language on the model, eg Payment.count().execute()
var Payment = thinky.createModel("payments", {
    id: type.string(),
    amount: type.number(),
    customerID: type.string(),
    project: type.string(),
    projectName: type.string(),
    projectPercentage: type.number(),
    firefundPercentage: type.number(),
    type: type.string(),
    processor: type.string(),
    email: type.string(),
    charged: type.boolean(),
    recharged: type.boolean()
});

module.exports = {
  model: Payment,
};

现在,他是否连接到rethinkdb的本地实例(2.4.1~0焦点)、我们在AWS上的分期或生产rethinkdb (2.3.5~0信任)并不重要。

我让他用nc -zv [url] 28015试了一下网猫,看看他是否可以连接,他成功地连接了ı。所以我不认为这是防火墙问题。

错误堆栈跟踪

代码语言:javascript
复制
node ./bin/www
  firefund:www Listening on port 3000 +0ms

node:events:498
      throw er; // Unhandled 'error' event
      ^


Error [ERR_STREAM_WRITE_AFTER_END]: write after end                                                                         
  at new NodeError (node:internal/errors:371:5)
    at _write (node:internal/streams/writable:319:11)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at Connection._sendProof (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:294:19)
    at /home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:248:12
    at Object.tryCatch (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/helper.js:170:3)
    at Connection._computeSaltedPassword (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:247:12)
    at Socket.<anonymous> (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:184:18)
    at Socket.emit (node:events:520:28)
    at Socket.emit (node:domain:475:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on Connection instance at:
    at Socket.<anonymous> (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:129:12)
    at Socket.emit (node:events:520:28)
    at Socket.emit (node:domain:475:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
        code: 'ERR_STREAM_WRITE_AFTER_END'
    }

堆栈跟踪表明它是节点_模块/rethinkdbdash/lib/connection.js中的连接错误。

connection.js

connection.js:第294行是底部的this.connection.write(Buffer.concat([new Buffer(message.toString()), NULL_BUFFER]))

代码语言:javascript
复制
Connection.prototype._sendProof = function(authentication, randomNonce, saltedPassword) {
  var clientFinalMessageWithoutProof = "c=biws,r=" + randomNonce;
  var clientKey = crypto.createHmac("sha256", saltedPassword).update("Client Key").digest()
  var storedKey = crypto.createHash("sha256").update(clientKey).digest()

  var authMessage =
      "n=" + this.user + ",r=" + this.randomString + "," +
      authentication + "," +
      clientFinalMessageWithoutProof

  var clientSignature = crypto.createHmac("sha256", storedKey).update(authMessage).digest()
  var clientProof = helper.xorBuffer(clientKey, clientSignature)

  var serverKey = crypto.createHmac("sha256", saltedPassword).update("Server Key").digest()
  this.serverSignature = crypto.createHmac("sha256", serverKey).update(authMessage).digest()

  this.state = 2
  var message = JSON.stringify({
    authentication: clientFinalMessageWithoutProof + ",p=" + clientProof.toString("base64")
  })
  this.connection.write(Buffer.concat([new Buffer(message.toString()), NULL_BUFFER]))
}

变异误差

他还报告了同样错误的变体,如下文所示:

代码语言:javascript
复制
node ./bin/www
  firefund:www Listening on port 3000 +0ms

node:events:498
      throw er; // Unhandled 'error' event
      ^


Error [ERR_STREAM_WRITE_AFTER_END]: write after end                                                                         
  at new NodeError (node:internal/errors:371:5)
    at _write (node:internal/streams/writable:319:11)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at /home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:143:23
    at Object.tryCatch (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/helper.js:170:3)
    at Socket.<anonymous> (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:142:12)
    at Socket.emit (node:events:523:35)
    at Socket.emit (node:domain:475:12)
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1143:10)
Emitted 'error' event on Connection instance at:
    at Socket.<anonymous> (/home/edel_weiss/firefund-production/node_modules/rethinkdbdash/lib/connection.js:129:12)
    at Socket.emit (node:events:520:28)
    at Socket.emit (node:domain:475:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
        code: 'ERR_STREAM_WRITE_AFTER_END'
    }

此变体表明错误位于connection.js中的第143行:

代码语言:javascript
复制
self.connection.write(Buffer.concat([versionBuffer, authBuffer, NULL_BUFFER]));
代码语言:javascript
复制
self.connection.on('connect', function() {
    self.connection.removeAllListeners('error');
    self.connection.on('error', function(error) {
      self.emit('error', error);
    });

    var versionBuffer = new Buffer(4)
    versionBuffer.writeUInt32LE(protodef.VersionDummy.Version.V1_0, 0)

    self.randomString = new Buffer(crypto.randomBytes(18)).toString('base64')
    var authBuffer = new Buffer(JSON.stringify({
      protocol_version: PROTOCOL_VERSION,
      authentication_method: AUTHENTIFICATION_METHOD,
      authentication: "n,,n=" + self.user + ",r=" + self.randomString
    }));

    helper.tryCatch(function() {
      self.connection.write(Buffer.concat([versionBuffer, authBuffer, NULL_BUFFER]));
    }, function(err) {
      // The TCP connection is open, but the ReQL connection wasn't established.
      // We can just abort the whole thing
      self.open = false;
      reject(new Err.ReqlDriverError('Failed to perform handshake with '+self.host+':'+self.port).setOperational());
    });
  });

如果你读了这么多-谢谢!

这两个错误都是关于写入Buffer的。

有人知道nodejs在Windows11?Buffer上的实现有什么相关问题吗?

EN

回答 1

Stack Overflow用户

发布于 2022-03-06 18:56:02

肯定不确定这是否是答案,就在这里吐口水吧,也许您可以让一个自定义的Buffer.concat函数工作,以防是nodejs Buffer.concat导致了这里的问题;-;希望它能在windows 10上运行。

代码语言:javascript
复制
function BufferConcat(buffers){ //buffers is the array of buffers
  var bytes=Buffer.byteLength, i=0
  var length=buffers.reduce((b1,b2)=>bytes(b1)+bytes(b2))
  const BufferToReturn=Buffer.alloc(length)
  for(let buffer in buffers){
    let values=Object.values(buffer)
    for(let item of buffer){BufferToReturn[i++]=item}
  }
  return BufferToReturn
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71372407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档