The Soviet Union has resumed sending military supplies to Somalia, apparently in an effort to dissuade the Somalis from turning to the West for arms and to protect itself should a pro-Western coup in Ethiopia make Somalia once again Moscow's primary East Afircan ally.

Several Soviet ships loaded with war material have recently arrived here, according to Arab and Western diplomatic sources, even as Moscow is pouring arms into neighboring Ethiopia. Somalia and Ethiopia, both having Soviet-backed, Marxist governments, are in a virtual state of war over a huge tract of disputed border territory, the Ogaden desert region of southeastern Ethiopia.

Earlier this summer, the Soviet Union suspended shipments of spare parts and new military equipment to Somalia, apparently out of deference to its new ally in Ethiopia, Lt. Col. Mengistu Haile Mariam, who visited Moscow in early May.

The suspension and quick resumption of shipments to this country neatly illustrates the dilemma the war in southeastern Ethiopia is posing for Moscow now that it has become the main military supplier and foreign backer of both Somalia and Ethiopia.

In its decision to rescue Mengistu lies the probability that it may lose Somalia, once its closest black African ally.Having committed itself to the beseiged Ethiopian military government, the Soviet Union is discovering that the massive arms lift necessary to assure its survival is unacceptable to the Somali government.

Ironically, everything indicates that the Soviet decision to supply arms to Mengistu was responsible for quickening the wars that may cause his downfall. Arab diplomats point out that the arrival of Soviet tanks in Addis Ababa beginning in March made it imperative for both the Somali-backed rebels in the Ogaden and the secessionist Eritrean insurgents in the middle to press for victory before the Mengistu government became too strong. In this undertaking, the rebels had the full backing of Somalia as well as of pro-Western Arab states in the Red Sea region that believe Mengistu is importing Soviet communism.

For the Soviets, Ethiopia represents a huge gamble, their second in black Africa in the last two years. In the first, the Angolan civil war of 1975-76, the Soviet-backed Popular Movement for the liberation of Angola defeated the pro-Western factions, but only with the help of a huge Soviet arms lift and more than 15,000 Cuban troops.

The Soviet victory there, against incredible odds, has apparently emboldened Moscow to take comparable risks in one affort to best the United States in the undeclared cold war in black Africa.

The stakes for the Soviet Union in northeastern Africa, however, are far greater than they were in Angola, where the Soviets had nothing to lose but prestige and everything to gain if their allies won.In northeast Africa, the gamble involves the future position of the Soviets in Somalia, Ethiopia and South Yemen, and the contest for influence between Saudi Arabia and the Soviet Union throughout the Red Sea region.

The Soviet Union has important vested interests here, as it did not in Angola. It stands a good chance of losing the use of Somali naval and airport facilities it built or improved along the Indian Ocean. It also runs the risk of losing its new ally in Ethiopia in the same kind of palace coup that brought Mengistu to power in early February.

It seems unlikely that Mengistu can maintain his power intact if Ethiopia is dismembered. Right now, his government is in deep danger of losing not only the Ogaden region and Eritrea but also large parts of four provinces in the Southeast.

Eritrean nationalists have seized all of Eritera except the provincial capital of Asmara and the Red Sea ports of Massawa and Asab, while Somali nationalists have control of almost all the Ogaden and are pushing into the highlands less than 150 miles from Addis Ababa.

If Mengistu falls, a new Ethiopian government, whether military or civilian, is likely to swing back toward the West and oust the Soviets. This is presumably why Moscow has decided that saving Mengistu is vital, even at the risk of alienating Somalia.

The Soviet Union, however, is far from being "out" of Somalia or even on its way to leaving. Contrary to recent Western press reports, there is no indication that large numbers of Soviet advisers are departing, although the number here is reportedly far fewer than the 4,000 to 6,000 so often cited. Western diplomatic sources believe there are no more than 2,500.

On the other hand, the spirit of the 1974 Soviet-Somali treaty fo freidnship and cooperation, the first Moscow signed with a black African state, appears to be dead and even the letter of that agreement my follow suit before long.

Somalis do not hide the dislike and often hate they feel for the Soviets because of Moscow's new "tilt" toward Ethiopia. "We feel a sense of betrayal," one Somali explained.

For the first time, criticism of the Soviet Union has appeared in the striclty controlled press. Horseed (the Avantguarde), and "independent" weekly written in Italian and Arabic, ran a series of anti-Soviet Articles in June. When Soviet Ambassador Georgy Samanov demanded the right to reply, he was refused.

It's like a marrriage that has gone sour but neither is the same as usual," a Somali journalist remarked.

President Mohamed Siad Barre has shown no interest in making a public issue of Somalu difference siwth the Soviet Union or of pushing them to the breaking point. Even the most optimistic pro-Western Arab diplomats here seem to rule out another Egypt," meaning a move comparable to the mass expulsion of Soviet Advisers ordered by Egyptian President Anwar Sadat in 1974.

"Siad is still very uncertain of the West," said one diplomat. "He does not trust you. Unless he is sure of getting arms from the West he cannot afford to break with the Soviets.

The United States, France and Britain have all publicly announced, or told said privately, that they will provide some arms, if only "defensive" ones, to Somalia. But it seems unlikely that these Western powers are ready to take over the Soviet military role here. At best, they may provide some small arms - one of the "urgent" items on Siad's current shopping list - and other military equipment that essentially complements rather than replaces the Soviet arsenal.

Britain and the United States are under pressure from pro-Western Kenya not to provide arms to Somalia, because the Somalia's have claims to Kenayan as well as Ethiopian territory. France, for its part, is committed to maintaining the independence of Djibouti, which Somalia holds to be rightfully part of the "greater Somalia" of all Somali-speaking peoples in the region.

Thus, all three Western powers confront an embarrassing conflict of interests in their regional African policies in attempting to help Somalia lessen its dependence on the Soviet Union.

Furthermore Washington must take into consideration the possibility that Mengistu's government will be replaced by a pro-Western military faction that would again ask for American arms and other aid.

The West's conflicting interests, however, are nothing compared to the Soviet Union's. Moscow will now undoubtedly seek a compromise solution that would protect its interests in both countries.

Yet, an attempt by Moscow to force Somalia to accept less than all the "lost territory" in Ethiopia it dreams of grabbing could well be the last straw for the Somalis, who think that a deep national aspiration is on the verge of fulfillment after 17 years of agitation, perserverance and bloodshed.

Moreover, said Barre may now be under too much political pressure at home to accept a compromise. Certainly he will not be disposed to save Mengistu, whom he calls a blood-thirsty murderer unworthy of support by any socialist country, just to please the Soviets.

Perhaps only a stalemate in the fighting, short of a total Somali victory, can get Mogadishu off what appears to be a collision course.