I am running openwhisk via jar on my development box. I can connect to mongo from node and from the command line. However, it times out when I try to connect from an openwhisk action.
curl -u $tok "http://172.17.0.1:3233/api/v1/namespaces/_/actions/openwhiskmongo?blocking=true&result=true" -X POST -H "Content-Type: application/json" -d '{"username":"jonboy"}' {"error":{"message":"Operation users.findOne()buffering timed out after 10000ms","name":"MongooseError","stack":"MongooseError: Operationusers.findOne() buffering timed out after 10000ms\n at Timeout.<anonymous> (/nodejsAction/hTFYlZze/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:153:23)\n at listOnTimeout (internal/timers.js:557:17)\n at processTimers (internal/timers.js:500:7)"}}
Mongo connects fine from the command line.
mongo mongodb://172.17.0.1
MongoDB shell version v4.4.17
connecting to: mongodb://172.17.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9777739e-0a81-4ef4-852a-a19a515ac376") }
MongoDB server version: 4.4.17
---
The server generated these startup warnings when booting:
2022-11-21T21:32:14.551-05:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2022-11-21T21:32:16.601-05:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
>
172.17.0.1 should be accessible via docker.
ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:efff:fecc:f630 prefixlen 64 scopeid 0x20<link>
ether 02:42:ef:cc:f6:30 txqueuelen 0 (Ethernet)
RX packets 153 bytes 11410 (11.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 278 bytes 7650054 (7.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Here's my action code.
openmongowhisk.js
const mongoose = require('mongoose');
async function main(args) {
require('./config/database');
require('./models/user');
const User = mongoose.model('User');
const name = args && args.username;
var result = 'not initialized';
var user = await User.findOne({username: name}).exec();
if (user) {
result = 'found';
} else {
result = 'not found';
}
return { user: user, result: result };
}
exports.main = main;
database.js
const mongoose = require('mongoose');
const devConnection = "mongodb://172.17.0.1";
mongoose.connect(devConnection, {
useNewUrlParser: true,
useUnifiedTopology: true
});
mongoose.connection.on('connected', () => {
console.log('Database connected');
});
user.js
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
id: String,
username: String,
});
mongoose.model('User', UserSchema);
Edit:add docker network info
[
{
"Name": "bridge",
"Id": "441a18a8d66ef7e29aaae1f2d5fee8b5e2f2edf39200b54a91f0df8b17407a46",
"Created": "2022-11-19T09:03:56.78026462-05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"13d0e2d487f03d2c806a917199857eefd77d9fb216eb9c68647ec5d7e93810e0": {
"Name": "wsk0_243_prewarm_nodejs14",
"EndpointID": "938de84937bfe214486713b4490645145a76f85cbff06f7ac49904beba9d8699",
"MacAddress": "02:42:ac:11:00:03",
"IPv4Address": "172.17.0.3/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]```
Any ideas?
I disabled the proxy settings on my computer, and now it is working. Can't believe I didn't think of trying that earlier.