3 ms·
We used (and actually still use) this to override hostname lookup in an automated test scenario, where we want to run multiple test suites of the same software
by Slartie 9y ago
We used (and actually still use) this to override hostname lookup in an automated test scenario, where we want to run multiple test suites of the same software (consisting of several processes which all communicate with each other via networking) on the same build server in parallel. We ended up just configuring everything to bind/connect to "localhost", so it runs fine on developer machines, but when executed on the build server - which is a lot more beefier than a dev laptop - the exact same configuration can be run 20 times, executing different test suites in parallel. The trick is that there's one independent loopback network interface for each run on that server, and by overriding the hostname lookup of the software via a small library provided in LD_PRELOAD, we replace the default lookup to 127.0.0.1 with these other loopback devices' IPs.
You could of course achieve the same thing (and even more, like filesystem isolation) in a way more elegant and better-understandable way via Docker containers, but we started doing this in 2011 - there was no Docker back then, so we built our own ultra-low-overhead network virtualization. It'll probably be replaced by Docker someday, but for the moment it's still being used as it "just works" and requires practically no maintenance after being set up once.
- jamespo 9y agoCouldn't you just bind to different addresses under 127.0.0.1/8 ? eg 127.0.0.1, 127.0.0.2 etc
- Slartie 9y agoNot if there isn't an interface. If I create one, sure, but then I would have to do that on all dev computers as well and I'd have to forward the address somehow into all server and client configs and/or command-lines of tools started as part of the build process. Just overriding "localhost" spares me from both (the address to resolve is provided as an env variable, just like LD_PRELOAD itself - and env variables are inherited by child processes, which is great in my scenario).
- jamespo 9y agoBut the loopback interface is up & available as standard? Only advantage I can see is if localhost is hardcoded everywhere.
- AnIdiotOnTheNet 9y agoYou can't just pass in which interface to bind via an environment variable or parameter?