It isn't a waste of time just because you know it will end at some point. I think we are taught to look at relationships like definite, final things, but I don't think that's always the best way to go about it. Relationships that aren't for forever can still provide you with wonderful experiences, something to learn from, and great memories. Someone who is good for you now may not be the one for you later on, but that's okay. Take it as it comes and see what happens. Not everyone you get with is going to be "the one," and that's okay. Do what feels good in the moment and just flow with it. Yes, there's a chance that you will get attached, but there's always risk of that in a relationship. If you're mentally and emotionally prepared for it to end, then it doesn't have to be a traumatic experience, but rather, something you look back on, fondly. Or something you look back on and say, "well, I learned from that one!" which is also valuable.
And really, who is to say it will end when it's supposed to end? I wasn't expecting to stay in my long distance relationship over a year later, but here I am. And I'm glad I just went with it. Do it if it feels right, and don't get caught up on the idea of something lasting forever. If it does, it will play out that way. If it doesn't, take it for what it is, and be happy with the experience.