Monday, October 29, 2007

Leverage Eclipse perspectives for different screen layouts

At work I use a three monitor setup for Java development. The machine is based on Windows XP and Eclipse 3.3. The individual views are spread out across the middle and right screens, the left one is mostly used for browser and email windows. Because I usually use a rather large font for code editing the center screen is entirely dedicated to the code editor.  The right screen contains outline, call hierarchy, source history, a console view, the package explorer and the task/warnings lists. All in all each and every pixel of this 2560x1024 area is used effectively for Java development.

However in the evenings I sometimes like to complete some unfinished task at home. Thanks to a VPN connection I have full access to the CVS server and everything else I need. However I do not want to have to synchronize and download all changes to the laptop before I start. Usually I leave open Eclipse on my office PC all the time. To save time I just connect to it via RDP. The problem with that is however the limited resolution of the laptop screen - it is only 1400x1050. I used to have VNC running and scroll left and right to see all of the office screens, but it is just to slow and there are keyboard issues with the notebook keyboard.

The main disadvantage with this setup was Eclipse - because the RDP resolution is smaller than the office desktop I could only see a small part of the views on the right screen. The first few times I reset the Java and Debug perspectives to their default configuration which docks all views inside the main window. While this worked, it is a real pain to rearrange the views again when I came back to work the next morning.

It took some time until I remembered the "Save perspective" feature. I have now set up my "normal" Java and Debug perspectives - stretched out across two screens - and a "single window" version for each of them. The only thing that needs to be configured now when I switch from desktop to laptop mode is found in the Window - Preferences - Run/Debug - Perspectices menu: When working from home I define the "simple" perspectives as the defaults, at work I choose the multi-head versions.

Monday, October 15, 2007

How to charge the iPod Touch's battery on Linux

I have never been very much into iPods before. Although people were all excited about the click-wheel and the great user experience I tried some of them and never shared the whole fuzz.

However when I first heard about the iPod Touch I was really fascinated. I watched the iPod Keynote from September 2007 and immediately like the iPod Touch. Usually I am not a person who buys products immediately after their release, but I figured they had had some time to get the worst bugs out of the iPhone; and as the iPod is undoubtedly nothing more than the "phone without the phone" I decided to give it a go and ordered it from the Apple Online Store on September 9th. Delivery was scheduled for the week starting Oct 1st and it promptly arrived on Thursday. As I had it delivered to the office address I suddenly noticed a lot of people coming to my desk...

I connected it to the office desktop (XP) where I had been using iTunes for quite some time already to manage the music I usually listen to while coding. Syncing was a breeze and I was really happy.

Because I did not have time to fully charge it at work and of course played around with the WiFi (which is a little heavier on the battery than just listening to music). So I decided to fully charge it over night at home. However that turned out a lot more difficult than I had imagined. Up to that point I had always considered charging a mobile device via the USB port something nobody could do wrong. However when I plugged it in after I had fired up my Ubuntu desktop it just very briefly showed the "charging" icon on the iPod's screen and immediately went back to "working on battery". The Gnome desktop presented me with a camera import wizard... I tried to disconnect and reconnect, even disabled all udev rules because I suspected one of the programs started upon the discovery of the new device to somehow confuse it - all to no avail.

When I booted into the Windows partition I still keep for emergencies, it started to charge immediately... Now this is some kind of platform tie in! I knew before that Apple's support for anything but OS X or Windows is virutally non-existant, but preventing people from charging the battery, just because of the "wrong" operating system?

It took me four more days, pounding Google with all sorts of keywords I could imagine - "ipod charge linux", "ubuntu ipod battery" and so on. Only when I got the idea to search for some combination of terms that contained "iPhone" I got to this: iPhone Now Charges in Linux.

That site contains the source for a kernel module that will send a short sequence of bytes to the iPod or iPhone that will tell it to start charging the battery. I find it very annyoing that stuff like this necessary to just recharge a device... Thanks to Matt Coyler I do not have to boot Windows just to charge my MP3 player. Great job!

Friday, October 05, 2007

Can't start server: Bind on TCP/IP port: No such file or directory

(Also see the follow-up post about some progress)

Today I was (again) facing a log file from a machine that had for some reason not been able to start a temporary MySQL daemon during the night to prepare for a streaming MySQL slave installation. The necessary 2nd daemon had created its new ibdata files, however just after that aborted the startup process with the following message:

Can't start server: Bind on TCP/IP port: No such file or directory
071001 23:09:55 [ERROR] Do you already have another mysqld server running on port: 3310 ?
071001 23:09:55 [ERROR] Aborting
071001 23:09:55 [Note] mysql\bin\mysqld.exe: Shutdown complete

As you can see, the port is a different one from the default MySQL port, so I can be sure there was no conflict with the primary instance. Even more curiously the same process has been working on that and other machines flawlessly for some time. However I remember having seen this message once before, but back then I did not have the time to look into it any further. We just restarted the streaming slave setup process and it went right through.

This time however restarting that process didn't work. It just aborted with the same message again. I especially wondered about the error message: "Bind on TCP/IP port: No such file or directory". What the hell is that supposed to mean? A colleague and I even had a look at the MySQL source code, but the "No such file or directory" message is not to be found in conjunction with the bind error message. I looked on the web but could not find any explanation where that comes from.

However because the process would fail repeatedly I had a look at port 3310:

netstat -an | findstr "3306"

You can tell this is a Windows machine. Use findstr is a poor man's grep for Windows. However what's more interesting is that there is a connection on 3310. However this is not due to someone having already bound that port for some sort of a service, but instead it is in use as a local endpoint for a connection to a SQL server instance (port 1433)!

It turned out to be the same problem we had some time ago with JBoss not being able to bind port 1099 on Windows 2003. We had not explicitly reserved port 3310 for private use by a user-controlled application, so Windows was free to assign it as a local endpoint to any process requesting a socket connection. This is probably due to the range of so called ephemeral ports. The name stands for a range of ports that make up the "local" end every time an application connects to a remote service. The default bounds for this range are from port 1024 up to 4999. As 3310 is right in the middle of this range, apparently chances are big enough to get bitten by this more than once in a lifetime. We have now added port 3310 (and 3306 for that matter, which was also missing) to the list of ports excluded from the dynamic assignments. Probably 3306 has never been a problem, because the primary MySQL instance is configured as an autostart service. I guess it starts early enough during boot so that the chances of anything else having claimed that port are very low. However there was most probably some luck involved, too...

This might also be a problem if you need a lot of outgoing connections on a machine. To configure the range for Windows 2003 Server, have a look at Microsoft's documentation on TCP/IP stack implementation details, specifically the section on the "TCP TIME-WAIT delay" in the Core Protocol Stack Components and the TDI Interface chapter (for Windows 2000 see this page). They are both linked from Knowledge Base article #908472

We will monitor the situation and see if we get any more troubles with this.

I still however do not get the "No such file or directory" part of the message...

To round things up here's another link on the topic of ephemeral ports and their meaning for network security: