First off sorry for the delay in responding, this site has been under maintenance and offline for a while. It’s possible that you have a co-dependent personality, which means that you are so dependent upon a relationship, that “the relationship” is more important than YOU in the relationship – this makes you prioritize the other person over yourself to the point of self-neglect, which is the pattern you describe. Sometimes the root cause of this personality type, is insecure attachment as a child, where you grew up feeling insecure, unsafe, maybe fearing abandonment or rejection from a parent or care-giver? This insecurity can carry over into adulthood, where you still fear the loss of a relationship (maybe through rejection, or as you mention death). Remember, fears are not necessarily realistic – they can be based on faulty thinking that has it’s roots in early life experiences. This fear of losing a relationship may be causing you to subconsciously avoid closeness with people, as a way of protecting yourself from potential hurt. So you may have an imbalanced psychological approach to relationships: on the one hand you are co-dependent so you over-value the relationship at the expense of your own needs, and on the other hand fear of some type of loss, causes you to avoid healthy closeness.
You need to start with developing healthy self-esteem. Your inner thoughts should not be self-critical, but rather they should be validating and self-compassionate. The most important relationship you will ever have is the one with yourself, so work on developing a healthier sense of self first. When this is in place, then you may view other relationships differently, and you may behave in healthier ways too, which will change your patterns.