News for hackers. Stuff that matters.
Re:Perl code that is syntactically correct only on Fridays by knodi123 on Wednesday February 16, 2022 @10:02AM (#30360846)
Ha. I had an intern who wrote code that blew up if the timestamp of our DB server was ever >= 1 second after the timestamp of our app server.

It couldn't fail at his desk, because he ran both servers locally while developing. And it wouldn't fail in production in the morning, since we had a cron job that synced the clocks at midnight. It took until after 5pm for the clocks to drift enough, meaning I was on call and the intern was not.

But the bug didn't crop up until his code had been in production for a couple of weeks, so it was a real pain in the neck to track down.

Re:Perl code that is syntactically correct only on Fridays by bentcorner on Wednesday February 16, 2022 @10:21AM (#30361081)
Personally I really don't like code that deals with time - it's too easy to place a "get time stamp" call anywhere in code. If it's down in the bowels of some piece of functionality trying to test it becomes a headache.
Re:Perl code that is syntactically correct only on Fridays by sandinmyjoints on Wednesday February 16, 2022 @10:31AM (#30361234)
This is one of those pieces of software engineering wisdom that only comes from experience. Try explaining to a newish dev why they shouldn't `const now = Date.now()` or whatever anywhere they want, but rather do it in one place for the lifecycle and pass it around, and they will look at you funny and think it's a waste of time. Classic case of simple vs easy. Time has the potential to complect everything it touches.
Re:Perl code that is syntactically correct only on Fridays by Spoom on Wednesday February 16, 2022 @11:25AM (#30362005)
Oh yes. Any time I see code that tries to do some kind of scheduling, the first thing I ask is if they have considered using a library someone else has written. Way too many things can subtly go wrong, but new folks tend to think it should be easy, because how hard can it be to work with dates?
Re:Perl code that is syntactically correct only on Fridays by munk-a on Wednesday February 16, 2022 @05:11PM (#30366491)
There are seven time zones in Indiana in the tz database[1] - this doesn't count the two most used ones America/Chicago and America/New_York there's also a Kentucky tz that slightly spills into the state. Whenever anyone makes any comment about dates and times being easy to compute I just mention that yes, there are seven time zones in Indiana. Now the actual issues tend to arise when software makes assumptions like "every second will actually occur", "each second only happens once", "every minute has 60 seconds", "every day has 86400 seconds" amongst a plethora of other bad assumptions... but those are a lot more complicated to explain. I like leaning on Indiana.

1. https://en.wikipedia.org/wiki/Time_in_Indiana#tz_database

Re:Perl code that is syntactically correct only on Fridays by VTimofeenko on Wednesday February 16, 2022 @05:59PM (#30367033)
A great collection of those "every minute has 60 seconds" assumptions and why they are incorrect:

https://yourcalendricalfallacyis.com/

Re:Perl code that is syntactically correct only on Fridays by hwc on Wednesday February 16, 2022 @09:35PM (#30368894)
I just want to specify International Atomic Time, relative to some universally-agreed-upon epoch, in nanosecond units.
Re:Perl code that is syntactically correct only on Fridays by withinboredom on Thursday February 17, 2022 @04:46AM (#30371297)
So without leap seconds/days, how does one keep their clocks in sync with reality?
Re:Perl code that is syntactically correct only on Fridays by etherealG on Friday February 18, 2022 @04:17PM (#30391243)
One realises that one’s time is relative anyway and any universal time is just one’s own will to join a collective agreement that one doesn’t have to abide by. Then one puts this notion aside and prefers not to worry oneself with such things.
Re:Perl code that is syntactically correct only on Fridays by withinboredom on Friday February 18, 2022 @04:48PM (#30391553)
Uh. No. In the northern hemisphere, winter is January for centuries and centuries. Almanacs that farmers use also agree with that, so we have food to eat. Reality is much more than just rich first-world comforts. The world is deadly, and we use calendars and time-keeping as a basic survival skill. So basic, you probably don’t even realize it’s there.
Re:Perl code that is syntactically correct only on Fridays by everforward on Friday February 18, 2022 @09:27PM (#30393879)
There's a difference here between time as a fundamental property of the universe, and "time", which is how we relate a bunch of physical phenomenon to that fundamental force.

That's the primary driver for complexity here. Time as a property is hard to deal with because we take something simple, like how many seconds have passed since some other point in time, and then we have to correlate it to the sun and the moon and how close the Earth is to the sun and what side of the Earth we're on, and etc.

It forces computers to wrap a simple understanding of the passage of time in a lot of context that makes no difference to the computer.

Getting rid of calendaring doesn't imply that no one knows when winter is; winter is still a function of time. It's a pretty simple algorithm to figure out whether a given month is winter or not. It's easy to derive that context from an absolute measurement of time. It's an incredible amount more difficult to go from our calendaring system to any kind of absolute time, because our calendaring is kind of arbitrarily made up to keep things in sync. It bears little semblance to the passage of time, because it's purpose is more about maintaining context (i.e. the sun rises early in the morning, it's winter in January, etc) than actually measuring the passage of time.

Re:Perl code that is syntactically correct only on Fridays by withinboredom on Saturday February 19, 2022 @03:17AM (#30395334)
I take it you don’t work remotely with a global team or been homeless? I understand your philosophy and largely agree with it. However reality is much more nuanced.
Re:Perl code that is syntactically correct only on Fridays by duxup on Wednesday February 16, 2022 @02:40PM (#30364699)
> because how hard can it be to work with dates?

Man they are so hard that you could go on for hours about it.

https://www.codingblocks.net/podcast/why-date-ing-is-hard/

Re:Perl code that is syntactically correct only on Fridays by tentacleuno on Wednesday February 16, 2022 @01:10PM (#30363452)
> because how hard can it be to work with dates?

Oh man, tell me about it. Timezones are the worst. No wonder so many people just give up and use Moment.js.

Re:Perl code that is syntactically correct only on Fridays by jwandborg on Wednesday February 16, 2022 @01:22PM (#30363635)
I've been bit by bugs when coming to moment.js from other languages. It's the only datetime library I knew of, before you'll tell me about all the others, that mutates the datetime object when you do arithmetic.
Re:Perl code that is syntactically correct only on Fridays by dheera on Wednesday February 16, 2022 @01:21PM (#30363611)
Use UTC UNIX timestamps (i.e. Date.now()) for ALL time-related processing and only convert to hours/minutes when taking input/output from the user.
Re:Perl code that is syntactically correct only on Fridays by mypalmike on Wednesday February 16, 2022 @03:37PM (#30365351)
That's a good starting point, and certainly good advice for marking current time and past times. But keep in mind that future event absolute UTC can change due to politics, e.g. a change in daylight savings rules, which is less rare than you might imagine (https://en.m.wikipedia.org/wiki/Daylight_saving_time_by_coun...). That concert scheduled a year from now at 8pm in UTC+5 might actually end up occurring at 8pm in UTC+6.
Re:Perl code that is syntactically correct only on Fridays by notreallyserio on Thursday February 17, 2022 @12:18AM (#30369775)
> certainly good advice for marking current time and past times

But not too far past!

Re:Perl code that is syntactically correct only on Fridays by aidos on Wednesday February 16, 2022 @01:47PM (#30363980)
Uh oh, we’re going there again. If you’re doing anything in the future, that’s not always the correct thing to do. (Instants vs wall time etc)
Re:Perl code that is syntactically correct only on Fridays by amalcon on Thursday February 17, 2022 @09:09AM (#30373184)
I once had briefly traveled into a different time zone (so briefly that I hadn't thought about it) when I received a phone call asking to reschedule a doctor appointment. I entered the new time into my calendar. Then, I was an hour late to the appointment. My phone had adopted the timezone of the cell tower, and the calendar assumed I had meant "local time where I scheduled the appointment".
Re:Perl code that is syntactically correct only on Fridays by misnome on Wednesday February 16, 2022 @07:45PM (#30368083)
But I want my 4pm weekly meeting to always happen at 4pm, even if DST changes.
Re:Perl code that is syntactically correct only on Fridays by dheera on Thursday February 17, 2022 @01:55PM (#30377087)
If DST changes and you live in a democracy, it's your fault. Vote against DST. If you don't get what you want unleash the wrath on your congress member, not the software.
Re:Perl code that is syntactically correct only on Fridays by anchpop on Wednesday February 16, 2022 @04:47PM (#30366225)
Hmm, I think you should use TAI over UTC because UTC has leap-second corrections, Which means that the current time + X seconds might not actually be X seconds from now
Re:Perl code that is syntactically correct only on Fridays by albrewer on Wednesday February 16, 2022 @11:00AM (#30361682)
I learned this the hard way. Now I wrap interactions with system time in a container class so that, if need be, I can finely control time inside my app in unit tests and debugging.
Re:Perl code that is syntactically correct only on Fridays by fegu on Wednesday February 16, 2022 @02:00PM (#30364178)
In Haskell, getting the time is an IO operation. Because of this one tends to use the exact pattern you recommend.
Re:Perl code that is syntactically correct only on Fridays by lordnacho on Wednesday February 16, 2022 @04:44PM (#30366176)
It's also one of those things that actually is simple in restricted cases, then when you try to generalise it blows up badly, and it blows up like a time bomb rather than a landmine. When a time bomb explodes you don't quite know when it was triggered, but you have to deal with it then and there, learning a heck of a lot about time libs in general before you can proceed. What's a leap second, which years have a leap day, are time zones connected to places somehow, and so on. Just so you can fix your calendar that's part of a larger app.
Re:Perl code that is syntactically correct only on Fridays by kodah on Wednesday February 16, 2022 @01:43PM (#30363929)
> Classic case of simple vs easy.

Personally, I think my definition of "simple" changed over time. Much of that was influenced by the depth of my knowledge of particular paradigms, whether that be software or knowledge of the subjects I was writing code for.

Re:Perl code that is syntactically correct only on Fridays by bitemix on Wednesday February 16, 2022 @12:09PM (#30362543)
Love the Rich references.
Re:Perl code that is syntactically correct only on Fridays by blowski on Wednesday February 16, 2022 @01:18PM (#30363559)
The PHP interops group recently added a Clock interface for this purpose. There were many comments along the lines of “what’s the point?”
Re:Perl code that is syntactically correct only on Fridays by zaphirplane on Wednesday February 16, 2022 @09:04PM (#30368700)
Using the same time from the start of the whole operation doesn’t sound broadly right, I’m thinking deadlines retries expire logging
Re:Perl code that is syntactically correct only on Fridays by chii on Wednesday February 16, 2022 @09:26PM (#30368831)
you pass around a time provider module, which you can (and should) mock in tests to ensure that nothing catastrophic happens if time drifts in ways you don't really expect.
Re:Perl code that is syntactically correct only on Fridays by artdigital on Wednesday February 16, 2022 @07:57PM (#30368213)
Move the date up a layer and pass it into the code that deals with it, makes it easy to write tests for it
Re:Perl code that is syntactically correct only on Fridays by jimmaswell on Wednesday February 16, 2022 @02:30PM (#30364593)
Not too bad testing these things with mocking libraries.
Re:Perl code that is syntactically correct only on Fridays by inquist on Wednesday February 16, 2022 @10:29AM (#30361194)
> an intern who wrote code .... his code had been in production

You get what you pay for, eh?

Re:Perl code that is syntactically correct only on Fridays by darkwater on Wednesday February 16, 2022 @11:47AM (#30362267)
A cronjob to sync the time instead of a proper NTP client doesn't sound that good either. I know that each place has its own weird things because historical reasons but NTP is quite ancient.
Re:Perl code that is syntactically correct only on Fridays by knodi123 on Wednesday February 16, 2022 @11:59AM (#30362433)
Our sysadmin was being paranoid about how many memory-resident programs we ran. he figured time syncing wasn't important enough to justify a daemon, so he just ran the ntpdate command on a daily schedule. It wasn't that bad - after all, how far can clocks drift in a single day!? ;-)
Re:Perl code that is syntactically correct only on Fridays by tristor on Wednesday February 16, 2022 @02:53PM (#30364851)
> he figured time syncing wasn't important enough to justify a daemon

Time synchronization is very arguable THE most important thing on a server (for numerous security related reasons).

How many moons ago was this incident? It's perhaps forgivable ignorance in the 90s... not so much today.

Re:Perl code that is syntactically correct only on Fridays by Dylan16807 on Wednesday February 16, 2022 @05:26PM (#30366667)
For security? Kerberos usually has a 5 minute tolerance. Are you saying that's wrong? Because if your hardware/firmware isn't literally broken you won't drift anywhere near that in a day.

NTP can't properly fix a clock like that either since it's often capped at adjusting the speed by one part per two thousand. At most, with a consistently wrong clock, that can handle about 30 seconds per day. Any worse than that and you won't see much advantage over ntpdate.

Re:Perl code that is syntactically correct only on Fridays by randomswede on Thursday February 17, 2022 @02:47AM (#30370526)
The bigger the clock skew, the harder it is to correlate events from logs. The harder it is to corelate, the more information needs to come from your machine-fueled winnowing stage, to the final inspection by eyeballs.

1-2 seconds is (probably) well within manageable. But, since you now know for SUER that you have clocks running at different speeds, you need to over-estimate the skew. And hope that the daily skewing is approximately constant over time.

So, yes, clock skew can have an impact on your security, because it makes event correlation (and followup on security incidents) harder.

Re:Perl code that is syntactically correct only on Fridays by Dylan16807 on Thursday February 17, 2022 @02:53AM (#30370549)
"It makes logs more annoying, and sometimes security needs logs" is a pretty weak connection, though. And it's a far cry from precise timing being "THE most important thing on a server". Is there anything more direct at all?
Re:Perl code that is syntactically correct only on Fridays by randomswede on Monday February 21, 2022 @10:14AM (#30416706)
It's basically a whole bunch of small "make it harder to correlate" issues. If you have a distributed system (which you probably do, if you care about time to the point of considering if daily ntpdate or continually running ntp-or-equivalent is better), you will probably end up with timestamps somewhere in a protocol.

This could be timestamps in a DB server, or similar.

You can then, if you have too-large skew, end up in the weird position that one of "things that have been commited in the DB is not yet showing up on the frontends" (if the time used as a cut-off for the frontend's query is lagging behind the DB server and the timestamp is set by the DB server) or "things that have been commited are not showing up when you query for SELECT timestamp <= NOW()" (if the DB server is lagging, and the timestamp is set by the client).

If that maters, well, that's really a business and data quality issue.

Some distributed systems will also try to figure out what skew you have across the whole system and then end up taking N times that skew, before it can consider data persisted (see for example Spanner ,and probably CockroachDB). If your distributed system relies on timestamps for consistency, and it doesn't self-discover the skew, you're basically not guaranteed whatever consistency guarantees that the distributed system claims to have.

Again, is this important? It really depends. Is it OK of your distributed data store drops some of your data on the floor and lets you clean up the mess? Sometimes, yes, totally. Is it OK if you get uniqueness guarantees violatedl because two thigs got the same unique ID? Again, sometimes, almost-unique is enough.

Fo most people, log correlation is probably the biggest point, though.

Re:Perl code that is syntactically correct only on Fridays by krick on Wednesday February 16, 2022 @12:32PM (#30362865)
Admin like that sound a lot worse than the intern. Unless maybe if it's an intern-admin...
Re:Perl code that is syntactically correct only on Fridays by xorcist on Wednesday February 16, 2022 @12:32PM (#30362881)
If you are to be paranoid about time, better be paranoid about stepping time. Time discontinuities can trigger bugs in the best of software.
Re:Perl code that is syntactically correct only on Fridays by shadowoflight on Wednesday February 16, 2022 @12:29PM (#30362825)
Guess it's time to change the `0` in that cronjob to a `*/12`.
Re:Perl code that is syntactically correct only on Fridays by tremon on Thursday February 17, 2022 @06:56AM (#30372149)
after all, how far can clocks drift in a single day!?

Well, having run a Linux kernel on OpenBSD's vmm: they can drift more than a single day in that time. I did have to resort to using an ntpdate cron job because ntpd just couldn't cope with the time dilation effect. The cron job was configured at * * * * * (i.e. every minute), which roughly translated to once every 180 wall-clock seconds (+/- 30s).

Re:Perl code that is syntactically correct only on Fridays by zaphirplane on Wednesday February 16, 2022 @09:01PM (#30368686)
It’s the size of the correction that can cause problems
Re:Perl code that is syntactically correct only on Fridays by mywittyname on Wednesday February 16, 2022 @01:46PM (#30363974)
I've done equally stupid things as a senior dev. The biggest difference, I guess, is that I had to fix the stuff I broke.
Re:Perl code that is syntactically correct only on Fridays by closeparen on Wednesday February 16, 2022 @06:12PM (#30367156)
Delivering real functionality in production (with code review from your mentor, of course) is absolutely standard at a Big Tech or hot startup internship.
Re:Perl code that is syntactically correct only on Fridays by mypalmike on Wednesday February 16, 2022 @03:45PM (#30365450)
Depends. FAANG interns can make (annualized) income at or near 6 figures.
Re:Perl code that is syntactically correct only on Fridays by amelius on Wednesday February 16, 2022 @03:43PM (#30365419)
To be honest, I wrote code that blew up after the time server updated the time from the network, a few seconds after booting.
Re:Perl code that is syntactically correct only on Fridays by barbs on Wednesday February 16, 2022 @08:08PM (#30368313)
I'm surprised that got through code review
Re:Perl code that is syntactically correct only on Fridays by knodi123 on Friday February 18, 2022 @09:32AM (#30386123)
This was the early 2000s, at a very small startup funded privately by a non-technical guy, and most of the technical staff was under 25. It's a big world, and best practices are not universal.