What's this all about?

I use this space to plot down my twisted ideas. I guess they’ll do better (read prosper) here than inside my tiny skull.

If you for whatever reason should want to learn more about me, I’d suggest you try to catch up.

Humble thoughts, humongous ramblings...

On iOS 4 and unlocking your iPhone from your computer

June 20 by Mattias Arrelid, tagged apple, iphone, unlock, passcode, remote and ux

Since installing the new shiny iOS 4 on my iPhone 3GS I’ve noticed that I sometimes have to unlock the phone for my computer (i.e. iTunes, Image Capure etc.) to be able to sync with it:

iPhone: You need to unlock the phone to sync it

This is a welcome (new?) feature: if I should ever lose my phone, I wouldn’t want someone else to be able to plug it into random computer X and just bypass the passcode and start syncing my images (or whatever might be of interest). So far so good, but what if your computer isn’t located within physical reach, like the Mac Mini I’ve got connected to my TV? Then you’d have to get up, walk over to the computer, unlock the phone, walk back to the sofa/keyboard and then try to sync again. Cumbersome (yeah, I’m lazy)! This could clearly be improved.

I’d suggest/expect that as soon as you connect your iPhone to your computer and it needs you to authenticate to unlock it, you should have the option to provide the passcode from the computer you’re trying to sync with (maybe within the notification sheet itself?) instead of having to enter it on the phone. I’ve suggested this to the masterminds at Infinite Loop (that’s rdar://problem/8111672 for you with access). If I should ever hear back from them, I’ll update this post accordingly.

Now let’s continue backgrounding those apps…

Oh dear, this is broken behavior

April 2 by Mattias Arrelid, tagged srv, apple, resolve, iphone and spotify

Soon after the release of Spotify 0.4.0 for the iPhone, a number of subscribers told us that they could no longer connect to our service. Strange? We surely did some thorough Q&A before releasing this little beast into the wild - how could we have missed something so fundamental?

Soon it became apparent that some of these subscribers actually were able to connect, but only if the troublesome phone in question was connected to a carrier data network. Huh? Connect the phone to your preferred Wi-Fi again, and the app would just stall during login again…

I really, really, really, do hate this kind of symptoms: a few of our loyal subscribers could no longer use our service, and there was no way for us to reproduce the problem. Neither had we seen this problem during testing, and trust me - we do test our release candidates on a broad variety of customer routers. So… what do do?

When problems like these occur, it’s great having subscribers telling us about them as soon as possible. Thanks to these subscribers, it soon became obvious that our application was unable to retrieve information about what Spotify servers it should try to connect to. How come? Time to dig deeper…

We use SRV records to be able to balance the load on our servers. When our Spotify clients start, they all construct a SRV record query. This query is then passed on to a system library that is supposed to perform the actual SRV lookup. On the iPhone, we’re using Apple’s DNS Service Discovery framework to perform this operation. So far so good…

Unfortunately, many customer routers have serious flaws in their implementations of how to handle these kind of queries. We’ve been working around most of those issues by making sure that the SRV record we use in our live system is limited in size, so that the majority of routers are able to process it. However, this problem was new to us - could some routers have broken enough implementations to make the query just hang forever?

Now the fun part begins - how the hell do you confirm your suspected culprit? Some sample code should get you going…

#include <stdio.h>
#include <dns_sd.h>

void callback(
            DNSServiceRef sdRef,
            DNSServiceFlags flags,
            uint32_t interfaceIndex,
            DNSServiceErrorType errorCode,
            const char *fullname,
            uint16_t rrtype,
            uint16_t rrclass,
            uint16_t rdlen,
            const void *rdata,
            uint32_t ttl,
            void *context) {

    static int counter = 0;
    printf("Callback called: %d\n", ++counter);
}

void processQueryForSRVRecord(const char *record) {

    DNSServiceRef sdRef;
    int context;

    printf("Setting up query for record: %s\n", record);
    DNSServiceQueryRecord(&sdRef, 0, 0, record, kDNSServiceType_SRV, kDNSServiceClass_IN, callback, &context);

    printf("Processing query for record: %s\n", record);
    DNSServiceProcessResult(sdRef);

    printf("Deallocating query for record: %s\n", record);
    DNSServiceRefDeallocate(sdRef);
}

int main(void) {

    const char *record = "_example._tcp.example.com.";
    processQueryForSRVRecord(record);

    return 0;
}

Isn’t that sample code just great? As a matter of fact, it’s so spanking great that it will put the exact finger on what is wrong. Try to compile it yourself, and then run it… Notice anything strange compared to what you think might happen if you just look at the source code?

Yepp, the application just hangs forever. Why? It’s trying to resolve a non-existing SRV record… and apparently such a call to DNSServiceProcessResult just hangs forever.

This is just plain wrong - the call should return almost straight away without our callback ever getting called. Instead it just hangs. If you’re into GDB, attach to your test app and notice the following call stack:

(gdb) bt
#0  0x00007fff8827ef82 in recvfrom$NOCANCEL ()
#1  0x00007fff8827eebd in read_all ()
#2  0x00007fff8828074c in DNSServiceProcessResult ()
#3  0x0000000100000da3 in processQueryForSRVRecord ()
#4  0x0000000100000ddf in main ()

So, what will happen if you query for a valid record and you’ve got a fucked up router somewhere in between you and the rest of the internets? You will experience the above behavior. Not that very alarming if you’re a developer just running a test app, but if you’re a subscriber to the Spotify service, you’ll get pissed. It should just work, right?

Exactly our thoughts, why we’re replacing Apple’s framework with libresolv instead. It’s been serving our Mac OS X desktop client well throughout the years, and it will power our next iPhone release as well. And yes, it handles troublesome routers (and invalid records if you should like) just the way you’d expect it to - returning an error code instead of just hanging.

That’s it. Thanks everyone for helping us troubleshoot this - it sure made the debugging much easier!

1

Why starring items in Google Reader on the iPhone is unintuitive

March 21 by Mattias Arrelid, tagged google, reader, rss, ux and iphone

Dear Google,

I’m trying to plough throw my news feed using your excellent Google Reader web app for the iPhone. The app primarily serves my mark interesting items now, then read them later need - I like to read selected items on my portable computer since it’s more flexible than the iPhone when it comes to bookmarking, browsing similar content etc. I perform this operation by skimming through all new items, marking “interesting” ones with a star.

So far so good, so what’s the problem then? Well, for some reason you’ve decided to put the option to star an item in its header. This works really well if an item doesn’t span more than one page, i.e. the height of the iPhone’s screen. If an item spans more than one page, you will have to scroll back (up) to the item’s title be able to star the item. Really cumbersome, especially for longer items. I’d propose you put the star option in the item’s footer instead, which currently has all other fancy options but starring….

Would you be kind enough to think about this prior to your next update to the iPhone Reader web app?

Yours truly,
Mattias

Music Hack Day Stockholm - The aftermath

February 19 by Mattias Arrelid, tagged music, hack, day, stockholm and programming

The first Music Hack Day Stockholm has now come and gone. Looking back at the hack day weekend and trying to sum it up wasn’t easy, so I’m going to cheat and use Eric Wahlforss‘ (Soundcloud) words; This has got to be the best #musichackday eva!!. Turned out he wasn’t just fooling around - a fantastic ~30 demos/presentations rounded up the event during early Sunday evening [2].

How come everything worked out so darn well then? I’d say we were lucky; lucky to convince some fantastic sponsors to help us out, and even more lucky to manage to attract so many brilliant attendees. Add to this a wonderful venue plus tasty drinks and meals. You want more? What about top notch API presentations, letting the attendees concentrate on the actual hacking itself with full focus? In short - great success! Some of our guests even claimed improved typing speed after a close encounter with the now (in)famous Swedish beer fridge

We also managed to get quite an amount of press coverage. Swedish public service’s Stockholm news (ABC) even broadcasted an interview with Henrik during the last day of the event.

Could we have done things differently? Of course! I’ll try to remember to add an option to the signup form where you can specify what can of food you’re into (vegetarian? vegan? plain ol’ meat?). Another thing that crossed my mind was the missing option during signup of sharing your contact details with the rest of the attendees - could have been useful if we wanted to publish a list of people that had signed up for the event…

I’m not going to rave on about this any longer. I’m looking forward to the next hack day already - if not only for the hacking so for being able to meet you all again! Until then… hack away!

1

Music Hack Day Stockholm is getting closer

January 19 by Mattias Arrelid

It’s going to be awesome. Totally awesome.

Hello world

January 16 by Mattias Arrelid

Hi, hola, hej, hello world!

It’s been awfully quite here for some time. That’s gonna change now.