emacs jedi : failed to start Jedi EPC server (a firewall issue)

Introduction

emacs is a powerful, and extensible development environment (and text editor!). In its default configuration, emacs provides an adequate programming environment for the Python programming language.

jedi is an auto-completion and static analysis library for Python. The emacs packageĀ emacs-jedi integrates the superb functionality of jedi into emacs.

The issue

The emacs-jediĀ install process is a success – that is, the installation runs as expected, and doesn’t report any errors or warnings.

However, when jedi:setup is run (and if the installation instructions were followed to a tee, will run when activating python-mode), the emacs instance hangs, and eventually the following error message is displayed:

Error (jedi): Failed to start Jedi EPC server.
*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.

The solution

There are a number of reported issues that might result in the above error message. However, the specific issue that I was experiencing appeared to be undocumented.

After some troubleshooting (using strace, lsof, tcpdump, and emacs’ internal debugger), I was able to determine the issue that I experiencing was a result of emacs being unable to communicate with the jedi server because of firewall configuration.

My home network is IPv4-only. As such, I had configured my system’s IPv6 firewall INPUT, OUTPUT, and FORWARD chains to use a DROP policy (with no way to reach ACCEPT).

Modifying the IPv6 firewall’s OUTPUT chain policy to ACCEPT resolved the issue.

Bonus

I thought that an alternative solution could be achieved by having the firewall gracefully block (i.e. REJECT) requests. However I soon discovered that iptable’s chain policy can only be a TARGET, and REJECT is a TARGET EXTENSION.