BewareMyPower commented on code in PR #301:
URL: 
https://github.com/apache/pulsar-client-node/pull/301#discussion_r1116781940


##########
src/Client.js:
##########
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+const tls = require('tls');
+const fs = require('fs');
+const os = require('os');
+const PulsarBinding = require('./pulsar-binding');
+
+const tmpCertsFilePath = `${__dirname}/cert.pem`;
+
+class Client {
+  constructor(params) {
+    if (typeof params.tlsTrustCertsFilePath === 'undefined') {
+      fs.rmSync(tmpCertsFilePath, { force: true });
+      const fd = fs.openSync(tmpCertsFilePath, 'a');
+      try {
+        tls.rootCertificates.forEach((cert) => {
+          fs.appendFileSync(fd, cert + os.EOL);
+        });
+      } finally {
+        fs.closeSync(fd);
+      }

Review Comment:
   There is a problem that each time a `Client` instance is created, the file 
will be removed, created and written. If multiple `Client` instances are 
created concurrently, race condition could happen.
   
   I'm wondering if there is a way to initialize the `cert.pem` when running 
`npm install`. It means that the CA will be created only once when users type 
`npm install`. It could also ensure the CA is latest and not changed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to