Fix case where port is missing

Forward port of 6d3b5b24fd4f82c1cbfbc4cade5246a0335f8dda to master